当URL来自不同的服务器jQuery.ajax失败 [英] jQuery.ajax fails when url is from different server

查看:111
本文介绍了当URL来自不同的服务器jQuery.ajax失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么jQuery.ajax()抛出一个错误,没有错误消息,如果您使用的URL与dfferent服务器?

Why does jQuery.ajax() throw an error with no error message if you use a URL with a dfferent server?

推荐答案

因为在浏览器中XMLHtt prequests实现跨域请求限制它的。您可以通过使用JSONP作为格式,否则你将需要请求服务器端代理解决这个问题。

Its because of the restriction on cross domain requests implemented in the browser for XMLHttpRequests. You can get around this by using JSONP as the format, otherwise you'll need a server-side proxy for the request.

AJAX文档上的 http://jquery.com

请注意:所有的远程(不在同   域)的要求,应符合规定   如GET当'脚本'或'JSONP是   的数据类型(因为它加载脚本   使用DOM脚本标记)。阿贾克斯选项   需要一个XMLHtt prequest对象   不可用于这些请求。   完整的和成功的功能   叫上完成,但不要   接收XHR对象;该beforeSend   和dataFilter功能都没有   调用。

Note: All remote (not on the same domain) requests should be specified as GET when 'script' or 'jsonp' is the dataType (because it loads script using a DOM script tag). Ajax options that require an XMLHttpRequest object are not available for these requests. The complete and success functions are called on completion, but do not receive an XHR object; the beforeSend and dataFilter functions are not called.

这篇关于当URL来自不同的服务器jQuery.ajax失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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