I need to pass json variable using AJAX. Here is my ajax function:
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script>
function emailchkforfrntend()
{
var key='7bc443a2a363b050bc94963baff4b2ac';
var email_id=$("#email_id").val();// email_id->input field id
$.ajax({
url: "targetURL/example.php",
type : "post",
dataType: "jsonp",
data : { "email_id": email_id, "key": key},
success: function(result){
alert('success');
},
error: function(XMLHttpRequest, textStatus, errorThrown){
alert('error '+errorThrown);
alert('status '+textStatus);
alert('response text '+XMLHttpRequest.responseText);
},
complete : function(){
alert('in complete');
}
})
.done(function(msg) {
alert('Inside done....'+msg);
if(msg!=0)
{
var obj = jQuery.parseJSON(msg);
//var p_fname=obj.p_fname;
$("#Result_Div").html("<b style='color:blue;'>already existing Member <i class='fa fa-thumbs-o-up'></i></b>");
}
else
{
$("#Result_Div").html("<b style='color:green;'>New Member <i class='fa fa-thumbs-o-up'></i></b>");
}
});
}
HTML code:
<input type="text" id='email_id' onkeyup="emailchkforfrntend();">
After calling to this function, everytime it is giving call to error function and the control is not calling .done(function(msg){})
. Also I am getting Jquery1112016992787341587245_1466413029814 was not called
in first alert of error function. I passed one dummy PHP script to URL, which inserts record into database, to check whether is it calling the URL or not, the call to that PHP is working but still it is calling error function instead of calling success function.
Is there anything that I am missing? what is supposed to be done in order to work this functionality?