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 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。