文章出處
文章列表
今天在開發的時候,遇到一個問題,$.get()
在 IE8 瀏覽器不起作用,但 Chrome,Firefox 卻是可以的,網上資料很多,最后發現是 IE8 默認不支持 CORS 請求,需要手動開啟下:
jQuery.support.cors = true;
//url 是跨域的地址
$.get(url, , function (data) {
//...
});
參考資料:Ajax call not working in IE8
后來發現上面的設置在 IE8/IE9 中無效,需要另外的解決方案:jQuery-ajaxTransport-XDomainRequest
示例寫法:
$.getJSON('http://jsonmoon.jsapp.us/').done(function(data) {
console.log(data.name.first);
});
// POST
$.ajax({
url: 'http://frozen-woodland-5503.herokuapp.com/cors.json',
data: 'this is data being posted to the server',
contentType: 'text/plain',
type: 'POST',
dataType: 'json'
}).done(function(data) {
console.log(data.name.last);
});
參考資料:IE8、9 下的資源跨域請求
文章列表
全站熱搜