带有ajax错误的xml文档解析器

时间:2011-11-05 11:19:15

标签: javascript xml ajax

我有一个ajax调用,数据类型是xml,只有IE显示'Type mismatch'错误,它在FF中工作正常。

$.ajax({
        url: url,
        data: term,
        type: 'post',
        dataType: 'xml',
        success: function(response) {
            //response= {"popup":{"errorFlag":"false","terms":"understanding","description":"Description of understanding"}};

            // Create the xml document from the responseText string.
            if( window.DOMParser ) {
                var xmlDoc = response;
            } else { // Internet Explorer
                xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
                xmlDoc.async="false";
                xmlDoc.loadXML(response); 
            }

})

1 个答案:

答案 0 :(得分:0)

你为什么不使用$.parseJSON

试试这个

$.ajax({
    url: url,
    data: term,
    type: 'post',
    dataType: 'json',
    success: function(response) {
        //response= {"popup":{"errorFlag":"false","terms":"understanding","description":"Description of understanding"}};
        // now access all elements regardless of the browser
        var flag = response.popup.errorFlag;
        var terms = response.popup.terms;
        var description = response.popup.description;
    }
});

正如费利克斯已经注意到的那样,您的回复是JSON: The Fat-Free Alternative to XML