无法在Internet Explorer 10上加载Google Cloud Endpoints

13

我正在开发一个网站,使用Google JavaScript客户端库加载一些通过Google云端点暴露的API。端点是用Python开发的,但我不确定这是否是一个因素。在Chrome、Firefox和Safari中一切都运行良好,但在Internet Explorer 10上出现以下错误:

SCRIPT5007: Unable to get property 'value' of undefined or null reference 
proxy.html, line 7 character 51

我正在使用类似Google文档中建议的代码加载客户端库:

<script type="text/javascript">
    Oversee.Init();
    function init() {
        console.log("starting to load endpoints");
        gapi.client.load("marketplace", "1", function() {
            console.log("finished loading endpoints");
        }, "//" + window.location.host + "/_ah/api");
    }
</script>
<script type="text/javascript" src="https://apis.google.com/js/client.js?onload=init"></script>

这将在控制台上输出以下内容:

starting to load endpoints 
SCRIPT5007: Unable to get property 'value' of undefined or null reference 
proxy.html, line 7 character 51
请注意,"finished loading endpoints" 这一行永远不会被输出。 在经过漂亮的打印后,proxy.html 中相关的代码似乎是这样的,特别是 document.getElementById('root').value,由于 document.getElementById('root') 为 null 或未定义。
gapi.load('googleapis.proxy', {
    callback: function () {
        return window['googleapis']['server']['initWithPath']
            .call(this, document.getElementById('root').value);
    },
    config: {
        // snipped
    }
});

我注意到,如果我重新加载页面,API 将成功加载,并在控制台输出以下内容:

starting to load endpoints 
finished loading endpoints 

我在使用本地开发服务器和托管在Google App Engine生产实例上的应用程序时,都遇到了上述问题。

有人成功地从Internet Explorer 10中调用Google Cloud Endpoints吗? 如果是这样,请问我的代码有什么缺失?

编辑:这个问题也出现在谷歌的示例Cloud Endpoints Web应用程序中。我在这里部署了一个副本:https://cloud-endpoints-demo.appspot.com,当在Internet Explorer 10上运行它时,会出现相同的错误。

编辑2: 我在这里创建了一个问题:https://code.google.com/p/googleappengine/issues/detail?id=10700

编辑3:Google的井字游戏示例中,这个问题也存在。我在这里部署了一个副本:https://cloud-endpoints-tictactoe.appspot.com;与其他演示一样,在Chrome和Safari上运行良好,但在Internet Explorer 10中失败。

编辑4: 我仔细查看了Google提供的proxy.html。在导致错误的脚本标记下面,有一个包括id为'root'的文本区域的body。

<body>
    <textarea id="root" style="display:none">/_ah/api</textarea>
    <div id="lcsclient" style="position:absolute;left:-10000px;"></div>
</body>

因此,看起来谷歌需要对proxy.html进行一些更改,以确保在Internet Explorer上执行javascript之前文档已加载 - 我是正确的吗?


问题:https://code.google.com/p/googleappengine/issues/detail?id=10700 被标记为已解决。 - TrophyGeek
3个回答

2
我曾遇到在IE 10和11中加载Google Earth插件的Google APIs时出现类似问题。我们唯一找到的解决方法(除了等待Google修复)是强制IE 10以IE 9模式运行。每个版本的IE都包含前一个主要版本的渲染引擎。您可以通过进入IE开发人员工具并设置要使用的IE渲染引擎来手动测试此功能。
您可以通过在HTML文件中添加以下meta标签来强制IE以特定模式呈现:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>

这个meta标签必须作为HTML文件中的第一个meta标签,否则IE会忽略它。其他浏览器会忽略这个meta标签。但是,这将使得整个页面都使用IE 9引擎进行渲染,因此您会失去IE 10和11中存在的功能。如果您需要IE 10的功能,则此解决方法将无法满足您的需求。如果IE 9兼容性是您需求的一部分,则可能有助于解决此问题。

此链接提供更多关于IE兼容性模式的信息


0
希望它能有所帮助:
var executeRequest = function(path, data, callback, method){
    var url = ‘YOUR_API_LINK' + path;
    $.ajax({
        url: url,
        type: method,
        dataType: 'json',
        data: data?data:null,
        success: function(data, status, xhr) {
        },
        error: function(xhr, status, error) {
        },
        complete: function(xhr, status) {
            var data = null;
            console.log('Request ' + url + ' completed');
            if (xhr.responseText && xhr.responseText.length > 0) {
                data = $.parseJSON(xhr.responseText);
            }
            if (callback)
                callback(data);
        }
    });
};

---------------

Simple call example of this function made in the same file :

---------------

var simpleGetUser = function(userKey, callback){
    this.executeRequest(
    '/user/v1/user/' + userKey,
    {/* If you got any parameters, put them here */},
    function (res) {
        if (callback)
            callback(res);
    }, 'GET');
};

祝你好运!


0

这一定是IE10 JavaScript的问题。同意你指出的,null值一定来自于document.getElementById('root')。你的页面通常不会包含这样的元素,而且名称也不够独特。我怀疑'root'元素应该由来自Google的另一段JavaScript创建,而正是那段其他的JavaScript代码失败了(悄悄地)。利用你强大的调试技巧朝那个方向寻找。很抱歉,我想提供更多帮助,但那将违反微软的条款和条件(如果我不为每个实例支付他们的费用,我就被禁止运行他们的软件)。

编辑:由于proxy.html包含有问题的JavaScript代码和'root'元素,Google可以通过改变元素的顺序来纠正它。合理地说,许多作者建议将JavaScript放在html body底部之前。如果你能引用自己的proxy.html副本,你可以在向Google抱怨之前尝试修复它。


根元素实际上是静态 HTML,位于脚本标签下方的 body 中(请参见问题中的 Edit 4)。我相信,由于在我玩过的两个 Google 示例中都以同样的方式失败,解决方案将不得不在 Google 的一边。 - Greg
已更新至问题编辑4。 - Martin Berends
proxy.html文件是由Google的云端点结构创建和提供的;不幸的是,我对此没有任何控制权。我只是调用gapi.client.load("myapiname", ...),而在内部,gapi.client.load会加载proxy.html以及其他一些内容。 - Greg

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接