我的任务是更新最初仅在IE中工作的网站,并使其使其正常工作。
我现在遇到一个错误:
对象不支持属性或方法'selectnodes'
从IE特定的Ajax调用到jQuery ajax调用后,AJAX调用的输出,该调用应该可以使用交叉浏览器:
这是调用的原始功能:
function XmlHttpRequestBlocking(url, http_type, return_xml, content) {
var http_request = new ActiveXObject('Microsoft.XMLHTTP');
if(http_request == undefined)
return undefined;
try
{
http_request.open(http_type, url, false);
http_request.send(content);
if(http_request.status == 403)
{
top.location = "Login.aspx";
return undefined;
}
else if (http_request.status == 200)
{
if (return_xml) {
return http_request.responseXML;
}
else {
return http_request.responseText;
}
}
else
return undefined;
}
catch(e)
{
return undefined;
}
}
然后将其替换为:
function XmlHttpRequestBlocking(url, http_type, return_xml, content) {
var x;
jQuery.ajax({
url: url,
type: 'GET',
async: false,
success: function (result) {
x = result;
}
});
return x;
}
现在,以下调用了该功能并尝试解析输出会产生错误"对象不支持属性或方法'selectnodes'" IE
var capture_station_list = XmlHttpRequestBlocking(g_get_status_url, "GET", true, "");
var stations = capture_station_list.selectNodes("//channel");
我认为返回的XML的格式必须不同?试图安装台的jQuery版本的输出显示[对象文档]返回。
这可能是正在发生的事情:
在原始代码中,该函数返回XML DOM对象。在新代码中,该函数返回jQuery XML文档。jQuery对象没有SelectNodes方法。一种方法是重写XML的解析,以便使用jQuery。在jQuery Parsexml文档页面上有一个简单的例子。在您的情况下,可能是:
var capture_station_list = XmlHttpRequestBlocking(...);
$(capture_station_list).find("channel").each(function(i, station) {
console.log(station);
...
});