0

我已经为跨平台应用程序加载了一个 xml。它在 android 中运行,在windows 手机中运行 ios 位失败。我在同一个文件夹中有 html 和 xml。

 xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
 xmlDoc.async = false;
 xmlDoc.load('BranchDetail.xml');
 var xmlrows = xmlDoc.getElementsByTagName("ROW");
 alert(xmlrows.length);

此方法适用于 IE 10 桌面浏览器。我在 android 和 Iphone 中使用 xmlhttp 请求方法。xmlhttp 请求方法在 WP8 IE10 中也不起作用

我也尝试将 xmlDoc = new ActiveXObject("Microsoft.XMLHTTP") 用于 WP IE 10。

用于android和ios的方法:

  xmlhttp = new XMLHttpRequest();
  xmlhttp.open("GET", "BranchDetail.xml", false);
  xmlhttp.setRequestHeader('Content-Type', 'text/xml');
  xmlhttp.send("");
  xmlDoc = xmlhttp.responseXML;
4

1 回答 1

0

我使用 ajax 编辑我的代码,现在它可以工作了。对于 windows mobile IE10,我们需要提供一个参数 isLocal 来访问本地文件夹中的文件。

 var url = 'BranchDetail.xml';
            $.ajax({
                type:'GET',
                dataType: "xml",
                url: url,
                async: false,
                isLocal: true, // For the Windows Phone
                success: function (xml) {
                    $(xml).find('ROW').each(function () {
                        var title = $(this).find('BRANCH_EN_NAME').text();
                        alert(title);
                    });
                },
                error: function (xhr, error, exception) {
                    alert(" - Exception: " + exception);
                }
            });
于 2013-11-14T07:20:59.450 回答