views:

766

answers:

2

I want to consume a web service using jquery's get function. There is no layer in between, since the javascript files are put on the same server as the web service is running on.

My code runs nicely in firefox, but in ie7 the problem arise. I'm quite certain that i know the answer: xml header states "text/html", and IE7 belives unfortunately that it is true.

So, what can i do to help IE to understand my xml-response as xml? cast/parse?

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, the append-stuff takes place in a separate function):

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

I have dealt with this problem before. The only way I found to solve it was to do a manual ajax call, take the response text, parse it as a DOM document, and then use that.

Jeff Ober
how manual? totally without jquery? or with jquery.ajax()?
Fontanka16
I had to do it manually at the time, but I think that jQuery now has an option to force a mime type on the response. Take a look at the 'dataType' option on jQuery.ajax's options parameter.http://docs.jquery.com/Ajax/jQuery.ajax#options
Jeff Ober
I used the information here: http://docs.jquery.com/Specifying_the_Data_Type_for_AJAX_Requests.
Fontanka16
A: 

My solution:

$(document).ready(function(){
    $.ajax({
        url: "http://server/X?op=find&amp;code=wru&amp;request=biografier&amp;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());
        }
    }); 
});
Fontanka16