邮差扩展得到回应,但我的jQuery的要求不 [英] Postman extension get a response, but my jquery request not

查看:222
本文介绍了邮差扩展得到回应,但我的jQuery的要求不的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我提出用邮差扩展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:

XMLHtt prequest无法加载   <一href="http://www.rfen.es/publicacion/ranking/resultsBySwimmer.asp?l=020039535&t=&p=0&e=50L-I" rel="nofollow">http://www.rfen.es/publicacion/ranking/resultsBySwimmer.asp?l=020039535&t=&p=0&e=50L-I.   没有访问控制 - 允许 - 原产地标头的请求的present   的资源。

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.

为什么会出现这种情况?

Why does this happen?

我的JavaScript code是简单的:

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;
    });
}

邮差扩展不在同一个域要么,为什么它得到回应?

The Postman extension is not on the same domain either, why does it get a response?

推荐答案

只是为了帮助未来的研究员寻找这个具体的问题:为什么邮差的工作和我的jQuery的不

Just to help future fellows seeking for this specific question: Why POSTMAN works and my jQuery don't!

答案很简单,实际上是:浏览器扩展允许这样做!

The answer is quite simple, actually: Chrome Extensions are allowed to do so!

普通的网页可以使用XMLHtt prequest对象从远程服务器发送和接收数据,但它们是由同源策略的限制。扩展不局限于此。一个分机可以与远程服务器的起源之外,只要第一次请求跨域权限。

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的要求不的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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