In my script, i want to do an ajax post, and get the response and do an alert with it.
JavaScript Code:
$.ajax({
type: 'POST',
url: '../client_controller/teste',
data: {form:$('#the-form-'+num).serialize(), key : num},
success:function(response){
alert(response);
},
},
});
And this is my example php code:
if($_POST['key']==1){
parse_str($_POST['form'], $searcharray);
$_SESSION['voo']=$searcharray;
print_r( $_SESSION['voo']);
}
It all works except when i alert the response, in the beginning it prints the response, but i also prints all my html and javascript page code.
Can anyone explain to me what im doing wrong and why this is happening?
Try this:
if($_POST['key']==1){
parse_str($_POST['form'], $searcharray);
$_SESSION['voo']=$searcharray;
print_r( $_SESSION['voo']);
exit();
}
Can you try this, You have added an extra closing bracket in your code },
$.ajax({
type: 'POST',
url: '../client_controller/teste',
data: {form:$('#the-form-'+num).serialize(), key : num},
success:function(response){
alert(response);
}
});