JQuery的AJAX的跨域调用和权限问题

JQuery的AJAX的跨域调用和权限问题

本文介绍了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调用一个更好的解决方案?

I ended up using YQL to solve the cross domain issue and although it works, YQL is really slow that's adding quite a bit of performance overhead. Can anyone suggest a better solution for cross domain JQuery calls?

推荐答案

设置数据类型设置为JSONP在你的。你必须确保响应正确的格式为它工作。维基百科对 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的跨域调用和权限问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-12 04:44