Server side:
....
$_SESSION[\'accountId\'] = $accountId;
$_SESSION[\'type\'] = $_POST[\'accountType\'];
echo \'1\';
return;
<
There are more useful parameters to the error callback. Try getting the textStatus.
error: function(XHR, textStatus, errorThrown) { console.log(textStatus); }
Check what that is.
A quick guess is that you meant to use dataType: 'text'
not 'text/plain'
. (Check documentation)
$.ajax({
type:'POST',
data: $("#flowFormSubmit").serialize(),
dataType:'text',
timeout:1000,
success:function(response){
if(-1 == response)
alert('fail');
else
alert('succeed');
}
});
1) go to the url in your browser (the one you're fetching with ajax)
2) set the error callback for the jquery ajax request.
did you forget:
header('Content-Type:text/plain');
on server?
in your php code, use json_encode to return the response
eg:
$response = array('success'=>1);
echo json_encode($response);
then in your ajax success function it should be
if (response.success == 1) { alert('success'); }
Try omitting the return statement from server-side code. As far as your error callback is concerned, use the following generic ajax callback code and let us know what the status, responseText, and statusText properties are when this fails:
function callback(response)
{
if (response.readyState == 4)
{
if (response.status == 200)
{
alert("Response Success:\n" + response.responseText);
}
else
{
alert("Response Error:\n" + response.statusText);
}
}
}
It might be a good idea to specify a URL option:
$.ajax(
{
url:'foo.php',
type:'POST',
...