JSONP calls not working with apple-mobile-web-app-capable=“yes”

走远了吗. 提交于 2019-11-27 06:30:40

问题


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?


回答1:


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



回答2:


Not sure if you're doing this already but have you added "callback=?" in your query params?

Check out the dataType section here for more info: http://api.jquery.com/jQuery.ajax/



来源:https://stackoverflow.com/questions/7747264/jsonp-calls-not-working-with-apple-mobile-web-app-capable-yes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!