I created a basic MVC REST API to just get a separate Person from a data source. All this works locally, but not when I deploy it to the server.
public JsonResult Get(int? id)
{
if (id != null)
{
Person p = personBl.Get((int)id);
return Json(p, JsonRequestBehavior.AllowGet);
}
return Json("");
}
My jquery call looks like this:
$.ajax({
type: 'GET',
url: 'http://localhost:50708/Persons/Get/',
data: { id: 20 },
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
alert(data.Name);
}
});
When I deploy it on my Windows 2003 server and call the Get function, it is always 404 (obviously, there is no View attachment since I just want json).
I am using jsonp call as the server is in a different domain.
$.ajax({
type: 'GET',
url: 'http://192.168.1.187:1500/Persons/Get/',
data: { id: 20 },
contentType: "application/json; charset=utf-8",
dataType: "jsonp",
jsonpCallback: 'jsonpCallback'
});
function jsonpCallback(data) {
alert('callback');
}
Any idea why the above doesn't work?
source
share