0

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 (e.g., added "?callback=? to the url, with or without jsonp attribute, etc...)

Any help would be great,

Thanks in Advance

Treckz
  • 3
  • 2
  • What are you trying to get around? Is the callback not actually getting called? – ArrayKnight Nov 22 '13 at 17:37
  • *Edited, sorry. Yes, the callback function is not getting called. – Treckz Nov 22 '13 at 17:38
  • 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. – ArrayKnight Nov 22 '13 at 17:39
  • Can you add what the service returns to your post? – Marvin Smit Nov 22 '13 at 17:39
  • Oh.. You sir are correct! It isn't. Right now it's defined by: [WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json, UriTemplate = "getAllNoticias")] How should I define it? I believe there's no ResponseFormat equal to JSONP. – Treckz Nov 22 '13 at 17:45
  • This question seems to address this: http://stackoverflow.com/questions/758879/asp-net-mvc-returning-jsonp – ArrayKnight Nov 22 '13 at 17:46
  • @MarvinSmit Service returns JSON, as it's not configured to return JSONP, I guess that's the main problem. – Treckz Nov 22 '13 at 17:48
  • the service endpoint should define `bindingConfiguration="webHttpBindingWithJsonP"` like `` – shakib Nov 24 '13 at 18:44

1 Answers1

0

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

Community
  • 1
  • 1
ArrayKnight
  • 6,956
  • 4
  • 17
  • 20