php - Jquery Ajax using json is getting a undefined value -
$.ajax({ type: "post", url: "check.php", data: "checkit=" + $("#checkemail").val(), success: function(response){ $("#usercheck").html(response.status); if(response.status == true){ alert("yay"); }else{ alert("dsfds"); } } }, 'json');
someone here suggested doing ajax returns using json...
here php file returning json..
$data = {success:true}; echo json_encode($data);
im getting undefined return. perhaps here point me mistake?
you missing
datatype: 'json'
and php wrong:
$data=array('status'=>true);
update
here few suggestions try:
1) 'datatype' (case-sensitive believe)
2) try using 'contenttype' option so:
contenttype: "application/json; charset=utf-8"
i'm not sure how it's used in request post url, not in response. see article more info: http://encosia.com/2008/06/05/3-mistakes-to-avoid-when-using-jquery-with-aspnet-ajax (it's written asp.net, may applicable)
3) triple check output of post url , run output through json validator absolutely sure it's valid , can parsed json object. http://www.jsonlint.com
hope of helps!
Comments
Post a Comment