问题描述
我使用 Postman 扩展发出 GET 请求并获得响应,但是如果我使用 jQuery 发出相同的请求,我会收到一个典型的错误:
I make a GET request using Postman extension and obtain a response, but if I make the same request using jQuery I receive a typical error:
XMLHttpRequest 无法加载http:///www.rfen.es/publicacion/ranking/resultsBySwimmer.asp?l=020039535&t=&p=0&e=50L-I.请求中不存在Access-Control-Allow-Origin"标头资源.
XMLHttpRequest cannot load http://www.rfen.es/publicacion/ranking/resultsBySwimmer.asp?l=020039535&t=&p=0&e=50L-I. No 'Access-Control-Allow-Origin' header is present on the requested resource.
为什么会这样?
我的 javascript 代码很简单:
My javascript code is simple:
function getTiempo (dni, piscina, prueba) {
$.ajax({
async: false,
type: "GET",
url: "http://www.rfen.es/publicacion/ranking/resultsBySwimmer.asp?l="+dni+"&t=&p="+piscina+"&e="+prueba
})
.done(function (data) {
console.log(data);
return data;
});
}
Postman 扩展也不在同一个域中,为什么会得到响应?
The Postman extension is not on the same domain either, why does it get a response?
推荐答案
只是为了帮助未来寻求这个特定问题的人:为什么 POSTMAN 有效而我的 jQuery 无效!
Just to help future fellows seeking for this specific question: Why POSTMAN works and my jQuery don't!
实际上,答案很简单:Chrome 扩展程序可以这样做!
The answer is quite simple, actually: Chrome Extensions are allowed to do so!
常规网页可以使用 XMLHttpRequest 对象从远程服务器发送和接收数据,但它们受到同源策略的限制.扩展并没有那么有限.只要首先请求跨域权限,扩展程序就可以与其源之外的远程服务器通信.
Regular web pages can use the XMLHttpRequest object to send and receive data from remote servers, but they're limited by the same origin policy. Extensions aren't so limited. An extension can talk to remote servers outside of its origin, as long as it first requests cross-origin permissions.
https://developer.chrome.com/extensions/xhr
这篇关于邮递员扩展得到响应,但我的 jquery 请求没有的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!


大气响应式网络建站服务公司织梦模板
高端大气html5设计公司网站源码
织梦dede网页模板下载素材销售下载站平台(带会员中心带筛选)
财税代理公司注册代理记账网站织梦模板(带手机端)
成人高考自考在职研究生教育机构网站源码(带手机端)
高端HTML5响应式企业集团通用类网站织梦模板(自适应手机端)