Power ie7 accepts jquery.get response as xml despite wrong headers

I want to consume a web service using jquery get function. There is no layer in between as the javascript files are placed on the same server as the web service.

My code works well in firefox, but there is a problem in ie7. I'm pretty sure I know the answer: the xml header says "text / html" and IE7 unfortunately believed it to be true.

So what can I do to help IE understand my xml response as xml? cast / disassemble?

XML:

<?xml version = "1.0" encoding = "UTF-8"?>
<find>
<set_number>005262</set_number>
<no_records>000005611</no_records>
<no_entries>000005611</no_entries>
<session-id>YGSNPECRDEJS4Y3U1A65HMTG9PYPI1UDY1PYNFN2RK4BCDGY2D</session-id>
</find>

      

Code (simplified, additional material takes place in a separate function):

$(document).ready(
    function(){      
        $.get(
            "http://server/X?op=find&code=wru&request=arbetsliv&base=rik01",   
            function(data){ 
                $("#wru").append($('no_records',data).text());
            },"xml"
    ); 
});          

      

+1


a source to share


3 answers


I have already looked at this issue. The only way I figured out to solve it was to do a manual ajax call, take the response text, parse it as a DOM document, and then use it.



+2


a source


My decision:



$(document).ready(function(){
    $.ajax({
        url: "http://server/X?op=find&code=wru&request=biografier&base=rik01",
        success: function(data){
            var xml;
            if ($.browser.msie && typeof data == "string") {
                xml = new ActiveXObject("Microsoft.XMLDOM");
                xml.async = false;
                xml.loadXML(data);                
            } else {
                xml = data;
            }
            $("#wsa").append($('no_records',xml).text());
        }
    }); 
});

      

+1


a source


The easiest way I've found is to just transform the result if needed.

$.get(
    // all your parameters here
).done(function (data) {
    if (typeof data === 'string') {
        data = jQuery.parseXML(data);
    }
    // data is now a Document for you to use here
});

      

+1


a source







All Articles