jQuery JSONP跨域调用不执行任何操作 [英] JQuery JSONP cross domain call not doing anything

查看:113
本文介绍了jQuery JSONP跨域调用不执行任何操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每当我通过jquery对我在本地或服务器上设置的任何页面进行JSONP调用时,我得到的只是静默处理. Firebug报告200正常,响应看起来正常.我设置警报框以在成功时弹出或 失败,但均未出现.我使用什么网址似乎都没有关系,什么都不会弹出.

Whenever I do a JSONP call through jquery to any page I set up (either locally or on my server) all I get is the silent treatment. Firebug reports 200 OK and the response looks ok. I setup alerts boxes to popup on success or failure but neither appears. It doesn't seem to matter what url I use, nothing pops up.

但是,如果我使用twitter json页面,那么我将按预期方式显示成功警报框,因此我的响应显然出了点问题,但是我不知道是什么.

BUT if I use the twitter json page then I the success alert box appears as expected so there is obviously something wrong with my response but I don't know what.

作为一个实验,我复制了twitter json响应并将其上传到我的booroo.com域.它应该是相同的,但仍然没有.我将响应页面上的标头设置为"application/json"和utf-8,但仍然没有设置.

As an experiment I copied the twitter json response and uploaded it to my booroo.com domain. It should be identical, but still nothing. I set the headers on the response page to "application/json" and utf-8 but still nothing.

请帮助,我已经花了整整一整天的时间,不知道还能尝试什么.

Please help, I've spent all day on this now and I don't know what else to try.

$.ajax({
  dataType: 'jsonp',
//  url: 'http://booroo.com/json.asp?callback=?',
  url: 'http://twitter.com/users/usejquery.json?callback=?',
  success: function () {
        alert("Success");     
    },
    error: function(x,y,z) {
        alert("error"+x.responseText);
    }       
});

响应json.asp文件包含以下经典的ASP标头,然后包含从twitter复制的json响应(我也尝试过其他应用,但均未成功).

The response json.asp file contains the following classic ASP headers and then the json response copied from twitter (i've tried others without any success either.)

<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<%
Response.Expires = 0
Response.Expiresabsolute = Now() - 1
Response.AddHeader "pragma","no-cache"
Response.AddHeader "cache-control","private"
Response.CacheControl = "no-cache"
response.ContentType="application/json"
Response.CodePage = 65001 
Response.CharSet = "UTF-8" 
%>({"test_param":12345});

推荐答案

晚上睡个好觉,我已经解决了这个问题.我没有意识到这是两种响应格式之间的区别.当我仅使用浏览器查询Twitter时,响应中没有包含使我感到困惑的函数名称.

OK after a good nights sleep I've solved the problem. I didn't realise these was a difference between the two response formats. When I queried twitter just using my browser the response didn't include the function name which confused me.

//JSON
{"name":"stackoverflow","id":5}
//JSONP
func({"name":"stackoverflow","id":5});

这篇关于jQuery JSONP跨域调用不执行任何操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆