网站的工作,但不是在iPhone上。 XMLHtt prequest()错误 [英] Website working, but not on iphone. XMLHttpRequest() error

查看:105
本文介绍了网站的工作,但不是在iPhone上。 XMLHtt prequest()错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了这个网站

http://www.tylertracy.com/testing/ XML /应用程序%20veiwer%205-28.php

它工作正常,大多数浏览器和iPhone模拟器,但它并没有一个真正的iPhone工作。我已经把范围缩小到XMLHtt prequest()。看来,当我收到的XML,我不能读[对象元素]的儿童则返回undefined。这是很莫名其妙的,我不明白。

It works fine on most browsers and on iPhone simulators, but it doesn't work on a real iPhone. I have narrowed it down to the XMLHttpRequest(). It seems that when I am getting the xml, I can not read the children of [object Element] it returns undefined. This is very baffling i do not understand.

下面是我的$ C $下获取XML

Here is my code for getting the XML

function convertXml (path) {
    if (window.XMLHttpRequest){
        xmlhttp=new XMLHttpRequest(); // code for IE7+, Firefox, Chrome, Opera, Safari
    }else{
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); // code for IE6, IE5
    }
    xmlhttp.open("GET",path,false);
    xmlhttp.send();
    xml=xmlhttp.responseXML.getElementsByTagName("app");
    var foo = [];
    for (var i = 0; i <= xml.length-1; i++) {
        foo[i] = {};
        for (var j = 0; j <=xml[i].children.length-1; j++) { // get all children of the app and make it a part in the object
            foo[i][xml[i].children[j].tagName] = xml[i].children[j].innerHTML.trim();//super complicated
        } 
     }
    return foo;
}

经过多次尝试我发现,在iPhone上请求返回[目标文件],而计算机返回[对象的XMLDocument。我不知道这是什么意思,但我觉得这是我的问题的根源。有这些之间可能转换的方式?

After much experimenting i have discovered that on iPhone the request returns a [object Document] while the computer returns a [object XMLDocument]. I don't know what this means, but i feel like it is where my problem is coming from. is there a way of maybe converting between these?

我从那时起更新code到jQuery的看到,如果问题仍然存在,而它的作用。

I have since then updated the code to jQuery seeing if the issue still persists, which it does.

下面是新的jQuery

Here is the new jQuery

function getXML (path) {
//gets text version of the xml doc
var response = $.ajax({ type: "GET",   
                    url: "testingXml.xml",   
                    async: false,
                  }).responseText;
//converts text into xmlDoc
parser=new DOMParser();
xmlDoc=parser.parseFromString(response,"text/xml");
return xmlDoc;
}

function xmlToObject (x) {
var xml = x.getElementsByTagName("app"); //get all the xml from the root
var foo = [];
for (var i = 0; i <= xml.length-1; i++) {
    foo[i] = {}; // make the object
    for (var j = 0; j <=xml[i].children.length-1; j++) { //get all of the children of the main tag
        foo[i][xml[i].children[j].tagName] = xml[i].children[j].innerHTML.trim();  //super complicated
    }
}
return foo;
}

然后拿到阵列,你会写这个code xmlToObject(的getXML(testingXml.xml))

该问题仍然发生,在电脑上是好的,但在iPhone(谷歌,Safari浏览器,火狐,奥普拉)看来,XML只是没有显示。

The issue is still happening, on computer it is fine, but on iPhone (Google, Safari, Firefox, Oprah) It seems that the xml just isn't displaying.

推荐答案

我收到

在主线程同步XMLHtt prequest是因为其不利影响到最终用户的体验pcated德$ P $。如需更多帮助,请查看 http://xhr.spec.whatwg.org/

Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience. For more help, check http://xhr.spec.whatwg.org/

打开网页时,谷歌浏览器的控制台。这可能是为什么它不会在iOS上加载。而不是只在记录警告,苹果决定在移动设备上这样的请求冻结忽视至prevent浏览器

in the Google Chrome console when opening your page. This could be why it won't load on iOS: instead of just logging a warning, Apple decided to ignore such requests on mobile devices to prevent the browser from freezing.

试着用

xmlhttp.open("GET",path,true);

和在<一个描述的 xhr.onload 处理程序href="https://developer.mozilla.org/en-US/docs/Web/API/XMLHtt$p$pquest/Synchronous_and_Asynchronous_Requests"相对=nofollow> MDN的同步和异步请求。

and a xhr.onload handler as described in MDN's "Synchronous and asynchronous requests".

这篇关于网站的工作,但不是在iPhone上。 XMLHtt prequest()错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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