So the solution to this was tricky.
Using JSONP you bypass the need to worry about cross-domain issues. However, When you set <meta name="apple-mobile-web-app-capable" content="yes" />
you will NOT be able to send cross domain requests without specifying Access-Control-Allow-Origin in your headers.
So here is the solution:
Note: In both of these requests I am specifying &jsoncallback=?
DOESN'T WORK:
function jsonpRequest(req){
$.getJSON(req,
function(data) {
// JSONP will run getJson() above;
});
}
DOES WORK:
function jsonpRequest(req){
$.ajax({
url: req,
dataType: 'json',
beforeSend: setHeader,
//data: data
//success: callback
});
/*
$.getJSON(req,
function(data) {
// JSONP will run getJson() above;
});*/
}
function setHeader(xhr) {
xhr.setRequestHeader('Access-Control-Allow-Origin', '*');
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…