weixin_33711647 2013-11-22 17:25 采纳率: 0%
浏览 31

JSONP请求回调

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

  • 写回答

1条回答 默认 最新

  • Didn"t forge 2013-11-22 17:51
    关注

    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

    评论

报告相同问题?

悬赏问题

  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler