The ajax function
function Verify(ccode,dgh)
{
str = "ccode="+ccode+"&dgh="+dgh;
console.log(str);//this outputs means that this functions gets called
$.ajax({
type: "POST",
url: "ajax/verify",
data: str,
async: false,
cache: false,
error: function (xhr, ajaxOptions, thrownError)
{
console.log(xhr.status);
console.log(thrownError);
},
success: function(json)
{
console.log("in-fun: "+json.code); //does not gets executed
return json.code; //does not return value
},
failure:function(response)
{
console.log("Ajax call failed"); //does not executes
}
});
}
the above ajax function is called as var e = Verify(var1, var2);
the value of e
is undefined after the ajax request.
The ajax request does hit my web server and visible in apache logs and dev tools and returns 200 OK. Ajax endpoint is working and does returns a valid json. The page output header is also set to json
EDIT: updated the above code
function Verify(ccode,dgh)
{
var retData = '';
str = "ccode="+ccode+"&dgh="+dgh;
console.log(str); // this works
$.ajax({
type: "POST",
url: "ajax/verify",
data: str,
async: false,
cache: false,
error: function (xhr, ajaxOptions, thrownError)
{
console.log(xhr.status); //does not gets called
console.log(thrownError);
},
success: function(json)
{
console.log("in-fun: "+json.code); //this does not ouputs anything
retData = json.code;
},
complete:function(response)
{
console.log("Complete called"); //does not gets called
}
});
return retData;
}