ie9 ajax 跨域請求不了 提交爲空 jquery-ajaxtransport-xdomainrequest

本問出自:

http://blog.csdn.net/wyk304443164

幾種方式:

  • 可以手動修改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>
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章