不能让CORS在chrome和firefox中工作
你好我试图ajax跨域调用,但标题有问题。 我遵循了许多教程,但我不能让它工作。
这是我走了多远:
jQuery.support.cors = true; $(document).ready(function() { //this would be done in a common script file if you are going to //make a lot of these calls $.ajaxSetup({ type: 'POST', dataType: 'json', contentType: 'application/json', data: {} }); $('#btn').click(function() { //call the web service with the button is clicked $.ajax({ url: 'url_external', data: '{ "some_data:data" }', //ensure the data is enclosed in a quote success: function (data) { alert('here...success'); }, complete: function (data) { alert('here'); } }); //return false to avoid a postback return false; }); });
这只适用于IE9。 我错过了什么吗? 在Mozilla Firefox和Google Chrome中,选项存在问题, 不允许使用405方法
将其添加到'url_external'
服务器上的所有HTTP响应中:
这将在您的url_external
服务器上启用CORS Ajax请求。
你可能想要对此进行微调......
header('Access-Control-Allow-Origin: http://yourdomain.com');
...仅允许来自您的域的CORS请求。
我发现的有关CORS的最佳信息: 使用CORS 。
- 为什么我的服务器忽略了ajax请求的身份validation标头?
- 当我尝试在响应头中获取具有Access-Control-Allow-Origin:*的图像的图像数据时,为什么会出现exception18?
- CORS问题 – 请求的资源上没有“Access-Control-Allow-Origin”标头
- CORS – Ajax错误函数将返回401的API请求的错误代码报告为0
- instagram jquery ajax type =“GET,无法绕过CORS
- Angular $ http.delete CORS错误(预检请求)
- 使用withCredentials和客户端证书使用jQuery的CORS请求失败
- 无法使用jQuery发送CORS POST请求
- 以jsonp发送请求,使用jQuery 1.5将响应解释为文本