JQuery ajax跨域调用和权限问题 [英] JQuery ajax cross domain call and permission issue

查看:237
本文介绍了JQuery ajax跨域调用和权限问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个轮询脚本来检查是否在服务器上创建了一个文本文件。在本地运行良好,但当文件在不同的域时失败。我将如何重写这个跨域支持?

I have this polling script to check if a text file is created on the server. Works great locally, but fails when the file is on a different domain. How would i rewrite this for cross domain support?

$.ajax({ 
    url: 'http://blah.mydomain.com/test.txt', 
    type: "GET", 
    success: function(result) { 
        //Success!
        window.location.replace(Successful.aspx');
    }, 
    error: function(request, status, error) { 
        setTimeout("VerifyStatus(" + pollingInterval + ")");
    }
    });

编辑:
我最终使用YQL解决跨域问题,虽然它的工作,YQL是真的很慢,这增加了相当多的性能开销。任何人都可以为跨域JQuery调用提供更好的解决方案。

推荐答案

将dataType设置为JSONP $ .ajax()呼叫。你必须确保响应格式正确,才能正常工作。维基百科有关于 JSONP 的好章节。

Set the dataType to "JSONP" on your $.ajax() call. You'll have to make sure the response is properly formatted for it to work. Wikipedia has a good section on JSONP.

这篇关于JQuery ajax跨域调用和权限问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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