ie9 ajax 跨域請求不了 提交為空 jquery-ajaxtransport-xdomainrequest
阿新 • • 發佈:2018-11-08
本問出自:
幾種方式:
- 可以手動修改ie9的允許跨域訪問(不實際)
- 使用jquery-ajaxtransport-xdomainrequest
api這邊
https://github.com/MoonScript/jQuery-ajaxTransport-XDomainRequest
// GET
$.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);
});
注意:如果post提交東西為空那麼可以修改為:
// contentType: 'text/plain',
contentType: 'application/x-www-form-urlencoded' ,
cdn:
<script src="http://cdnjs.cloudflare.com/ajax/libs/jquery-ajaxtransport-xdomainrequest/1.0.3/jquery.xdomainrequest.min.js"></script>