0

I am using ajax to download an xml about Sharepoint 2010 search (packet query). However the issue is when I try to traverse the xml using jquery.

$(document).ready(function() {
    String.prototype.endsWith = function(suffix) {
        return this.indexOf(suffix, this.length - suffix.length) !== -1;
    };

    var timeout = null;
    $('#SearchInputBox').on('keyup', function () {
        var text = $(this).val();
        if (timeout !== null) {
            clearTimeout(timeout);
        }
        timeout = setTimeout(function () {
            $('#LoadImage').show();
            DoSearch(text);
        }, 1000);
    });
});

function searchComplete(xData, status) {
    $('#LoadImage').hide();
    var search_results = $("#result");
    search_results.html('');

    $(xData.responseXML).find("QueryResult").each(function() {
        var err;
        try {
            var obj = $(this).eq(0);

            var text = obj.text(); // works in Firefox and Chrome but not IE9
            //var text = obj.text;
            //var text = obj.xml;

            var x = $("<xml>" + text + "</xml>");
            var docs = x.find("LinkUrl");
            var len = docs.length;
            var link;

            for(var i=0; i<len; i+=1) {
                link = $(docs[i]).text();
                if (link.toLowerCase().endsWith(".pdf")) {
                    search_results.append(link + "<br/>");
                }
            }
        } catch(err) {
            search_results.text("An error occured: " + err);
        }
    });
}

In this code, I retrieve the xml data, then try to display it on the browser. This works in firefox and chrome, but not IE9. I need it to work in IE9.

It fails on the .text() method, and also if I try .html() it fails there too.

I think there might be some browser specific things going on with the .text() method or maybe I need to parse the xml using http://api.jquery.com/jQuery.parseXML/.

Does anyone know how to fix this?

Thanks.

2 Answers 2

1

As you said in your question, you need to parse it as XML, not HTML.
Call $.parseXML

Sign up to request clarification or add additional context in comments.

1 Comment

@omega: $.parseXML been in jQuery since v1.5 (docs).
0

Given you're using jQuery already, why don't you just use jQuery.ajax() to make the request? It will help with a lot of cross-browser inconsistencies, and jQuery will make an "intelligent guess" at the response type and parse it automatically for you. You could also specify it with the dataType option.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.