【问题标题】:AJAX Cross-Domain problemAJAX 跨域问题
【发布时间】:2011-07-05 06:25:14
【问题描述】:

我有以下问题。我的 webapp 正在运行

http://webapp.mysite.com/browser/

我想提出一个请求

http://mysite.com/request?....

如果我使用第二个 url 进行标准 ajax 调用,我会收到一条错误消息 ,域(同源)策略错误。

 [object Object]-error-[Exception... 
  "Component returned failure code: 0x80004005 
  (NS_ERROR_FAILURE) [nsIXMLHttpRequest.send]"
   nsresult: "0x80004005 (NS_ERROR_FAILURE)"  
   location: "JS frame :: ..../scripts/jquery/js/jquery-1.4.4.min.js ::
   anonymous :: line 16"  data: no]

现在我尝试this ajax php proxy 来解决我的问题。但脚本不返回任何内容。

var app = 'http://www.mysite.com/rest.php?request=credits';
var proxy = 'proxy.php?proxy_url=' + app;

$.ajax({
    url: proxy,
    cache: false,
    async: false,
    dataType: 'html'
    success: function(html){
         alert(html);
    },
    error: function(){

    }
});

有什么想法吗?

【问题讨论】:

  • 服务器端发生了什么?是否调用了服务器端?我认为您必须在服务器上搜索问题。脚本被调用了吗? $h->body的内容是什么?

标签: ajax cross-domain-policy


【解决方案1】:

啊,可能是这个问题:

http://api.jquery.com/jQuery.ajax/

“跨域请求和dataType:“jsonp”请求不支持同步操作。”

你说,你会使用跨域请求,所以你不能将async设置为false。请尝试使用 async = true 并提供反馈。

啊,您是否收到内容为空的警报消息?

【讨论】:

  • 我用它来验证,所以 async 需要为 false。是的,我收到一条空警报消息