I trying to call cross domain call from jquery. The functions steps into error section with the error message, "alertResponse was not called". I am using Jquery version "jquery-1.6.2" and I am able to view the result of action checkSession in browser using "http://localhost:123/Home/CheckSession". Also in the visual studio debugger, the browser is loaded with the actual result returned from above url. But I am unable to get the value from the jquery.
Please find the Jquery code below: The Jquery code is in different domain - http://localhost:7451/TestPage.aspx
$(document).ready(function () {
SetActionItemCount();
});
function SetActionItemCount() {
var URL = "http://localhost:123/Home/CheckSession";
function alertResponse(data, status) {
alert("data: " + data + ", status: " + status);
}
$.ajax({
url: URL,
dataType: 'jsonp',
jsonp: 'callback',
jsonpCallback: 'alertResponse',
success: function (jsonp) {
alert(jsonp);
},
error: function(xhr, status, error) {
alert("error");
}
});
}
Server side MVC action method - this code is in "http://localhost:123/Home/CheckSession"
public JsonResult CheckSession()
{
string status = string.Empty;
status = "test data";
return Json(new { status },JsonRequestBehavior.AllowGet);
}
I am not sure what is that I am missing here. Also, when I run the jquery with debugger attached to localhost:32088, I get the debugger in checksession action method and it does return the value. But I am unable to get the value in jquery.
The output that I receive when I try the url "http://localhost:123/Home/CheckSession" in browser is {"status":"test data"}
Any help is much appreciated.