JSONP调用不适用于Apple-Mobile-web-app-capable =“yes” [英] JSONP calls not working with apple-mobile-web-app-capable="yes"

查看:122
本文介绍了JSONP调用不适用于Apple-Mobile-web-app-capable =“yes”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题:
< meta name =apple-mobile-web-app-capablecontent =yes/> set,我的所有jsonp请求都被拒绝。我通过设置content =yes来阅读,您无法更改页面。但我不知道你无法请求外部资源。并且此应用全屏。有没有办法在html5应用程序上使用此标签将iPad设置为全屏模式?

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?

现在我的请求只是被发送到另一个子域而且它们都是被拒绝?任何人都知道如何解决这个问题?允许jsonp并强制全屏模式?

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?

推荐答案

所以解决这个问题很棘手。

So the solution to this was tricky.

使用 JSONP ,您无需担心跨域问题。但是,当您设置< meta name =apple-mobile-web-app-capablecontent =yes/> 时,您将 NOT 能够发送跨域请求而无需在标头中指定Access-Control-Allow-Origin。

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.

所以这是解决方案:

注意:在这两个请求中,我都指定& jsoncallback =?

Note: In both of these requests I am specifying &jsoncallback=?

不起作用:

function jsonpRequest(req){
    $.getJSON(req,
      function(data) {
        // JSONP will run getJson() above;
    });
}

工作:

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

这篇关于JSONP调用不适用于Apple-Mobile-web-app-capable =“yes”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆