简体   繁体   中英

JSONP request callback

Ok, after an whole day trying to get this to work I just don't seem to know what's the deal with this, so here it goes:

I have a WebService hosted locally by now (http://localhost:15021/Service1.svc/[whatever_method]) and an HTML Page on a different file.

FYI, both WebService and HTML Page will get hosted on different servers.

I'm trying to get some info off the WebService to the HTML Page by the onload=load() method in the HTML Page.

My JavaScript code is:

function load() {
    alert("Loading...");
    $.ajax({
        url: 'http://localhost:15021/Service1.svc/getAllNoticias',
        type:'GET',
        dataType: 'jsonp',
        jsonp: 'loadNews_callBack'
    });
}

function loadNews_callBack(result){
        alert(result.data);
}

Additionally, the JSONP is loaded on the Page with an OK (200) status (As you can see here) which should (I guess) call the callback function, but it isn't .

What can I do to get around this? I already change the request parameters 500 times (eg, added "?callback=? to the url, with or without jsonp attribute, etc...)

Any help would be great,

Thanks in Advance

Check the actual response text to verify that the response is correctly being wrapped by the callback function. It is possible that your service is not setup correctly to handle JSONP so it simply responding with JSON. It will still come back as 200, but fail to execute.

loadNews_callBack([json...])

vs

[json...]

See this question as reference on how to go about updating your service: ASP.net MVC returning JSONP

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM