Deploy REST MVC3

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?

+3
source share
2 answers

I do not see how you use JSONP. Your server still returns plain JSON:

return Json(p, JsonRequestBehavior.AllowGet);

which will be sent this way by cable:

{ firstName: 'John', lastName: 'Smith' }

The JSONP response will look like this:

callbackname({ firstName: 'John', lastName: 'Smith' })

jsonp = > , .

JsonpResult, .

+2

, 1500? ? - http://192.168.1.187:1500/Persons/Get/ .

0

All Articles