本问出自:
几种方式:
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>