Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/370.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/83.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 为什么让python请求有效而jQueryAjax获取无效?_Javascript_Jquery_Ajax_Web Scraping_Python Requests - Fatal编程技术网

Javascript 为什么让python请求有效而jQueryAjax获取无效?

Javascript 为什么让python请求有效而jQueryAjax获取无效?,javascript,jquery,ajax,web-scraping,python-requests,Javascript,Jquery,Ajax,Web Scraping,Python Requests,我正在尝试使用Jquery进行ajax调用,以从网站检索json数据。我无法让它在Jquery中工作,但我能够使用python请求库使其工作。如何使用jquery获取ajax数据 这段代码可以工作并获得我想要的数据(但是,我希望它是客户端而不是服务器端) 此代码不适用。这是我想工作的代码。到目前为止,它只命中fail函数 $.ajax({ url: 'http://volaris.com/locations/json/autocomplete/?term=tij&where=&a

我正在尝试使用Jquery进行ajax调用,以从网站检索json数据。我无法让它在Jquery中工作,但我能够使用python请求库使其工作。如何使用jquery获取ajax数据

这段代码可以工作并获得我想要的数据(但是,我希望它是客户端而不是服务器端)

此代码不适用。这是我想工作的代码。到目前为止,它只命中fail函数

$.ajax({
    url: 'http://volaris.com/locations/json/autocomplete/?term=tij&where=&loc=&lang=en',
    type: 'GET',
    daType: 'json',
    cache: true,
    error: function() {
        alert( "ajax error" );
    },
    success: function(json) {
        alert( "ajax success");
    }
});

我想你看起来是那样的@Pavlo看起来不像那样。OP正在发出跨域请求;这似乎就是问题所在。我纠正了问题中的一些错误。没什么大不了的。从我所读到的内容来看,XDR似乎是个问题,但我对它了解不够。python请求库不是也是一个XDR请求并且有同样的问题吗?python与JS不受相同的源策略约束……为了解决这个问题,我只是使用我的服务器作为ajax调用的代理。
$.ajax({
    url: 'http://volaris.com/locations/json/autocomplete/?term=tij&where=&loc=&lang=en',
    type: 'GET',
    daType: 'json',
    cache: true,
    error: function() {
        alert( "ajax error" );
    },
    success: function(json) {
        alert( "ajax success");
    }
});