跨域JsonP请求无法在移动应用上运行

时间:2013-11-29 11:37:09

标签: jquery ajax jsonp mobile-application appframework

我正在尝试对服务器中的php文件进行jsonP调用,该服务器返回json值。我正在使用英特尔应用程序框架,它建议使用$ .jsonP进行跨域请求以克服同源限制。我已经尝试了以下代码,但它在页面中没有任何作用,因为我希望从php文件中生成json响应的无序列表。

 $("#search-form").submit(function(event) {
          event.preventDefault();
            $.jsonP({url:'http://dummysite.com/mobile/jsondata.php?&callback=?',
            success:function(data){
            $.each(data.userdata, function(i,user){
            var userList =
            "<ul>"
                +"<li>"+user.first+"</li>"
                +"<li>"+user.last+"</li>"
                +"<li>"+user.email+"</li>"
                +"<li>"+user.city+"</li>"
                +"</ul>"
                $(userList).appendTo("#results");
                });
            }}

        )});

更多信息 我使用#search-form提交表单时触发上面的功能。 event.preventDefault,避免表单默认提交,然后是一个jsonP请求到一个名为jsondata的回调的php文件。

成功后,我运行一个循环并在无序列表中填充数据。一切似乎都对我好,但无法弄清楚为什么它不起作用。

更新 我正在

  

Uncaught SyntaxError:意外的令牌:

在控制台中。当我提交表格时。

0 个答案:

没有答案