Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
471 views
in Technique[技术] by (71.8m points)

jquery - JSONP calls not working with apple-mobile-web-app-capable="yes"

The Problem: With <meta name="apple-mobile-web-app-capable" content="yes" /> set, all of my jsonp requests are getting denied. I read that by setting content="yes", you cannot change the page. But I was unaware you couldnt request external resources. And this app has to be full screen. Is there way around using this tag to set the iPad to full screen mode on an html5 app?

Right now my requests are just being sent to another subdomain and they are all getting denied? Anyone have an idea on how to get around this? Allow jsonp and force fullscreen mode?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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', '*');
    } 

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...