views:

392

answers:

6
+2  Q: 

PHP XML IE problem

<?xml version="1.0" ?> 
<NBR>
    <resultGroups>
    <result>Hello</result> 
    </resultGroups>
</NBR>

i have a n xml created in PHP ike this. i am retruning this XML into javascript and is trying to acces the value of node "result" using

alert($(xmlObj).children('result').text());

In firefox its working fine. but in IE it gives out nothing...

how can i solve this???

+1  A: 

It could be you are not sending the correct XML Content-Type header. You should send Content-Type: text/xml with XML content. You should also check that you set the correct charset in both the headers and the file. IE should be able to parse a correct XML response just fine if the JS code is correct and your XML response is valid.

Jani Hartikainen
my code already have it......stil no choice!!!!!!!!!
Jasim
make sure that it is the very first part of the reponse, otherwise the header will have already been set to something else.
Bingy
A: 

Have you tried parsing the data out before alert'ing it, and possibly using find instead?

var node_text = $(xmlObj).find('result').text();
alert(node_text);

Otherwise i would suggest trying to change the result tag to something different (like theresult) - everyone knows IE likes to do strange things! :)

danrichardson
+1  A: 

My guess would that is has something to do with the text() function. I am a Prototype guy myself but I ran into a similar problem with IE a little while ago. It came from me trying to pull the textContent value from an element in the DOM. I could grab the value in all other browser but IE was giving me the shaft. After running some tests, this is what I came up with:

IE does not support element.textContent. In most browsers, like FireFox, you would be able to pull the textContent value from element.

Example

<p id="my_element">this is my element</p>
alert($('my_element').textContent); // will alert "this is my element"

In IE, you need to use element.innerHTML. This will return the value you want. Right now, I assume that text() is returning the textContent value and that is why you're getting no dice.

Example

<p id="my_element">this is my element</p>
alert($('my_element').innerHTML); // will alert "this is my element"

Hope this helps!

Max Felker
A: 

If <result> is inside <resultGroups>, then try:

alert($(xmlObj).children('resultGroups').children('result').text());

or, you could try:

alert($($($(xmlObj).children('resultGroups')).children('result')).text());

or even:

alert($($(xmlObj).children('result')).text());

Let me know if any of these work.

Pedro Cunha
You are just creating multiple jQuery objects and gaining no real value from it.
PetersenDidIt
He could be using Prototype. If he is using Prototype, it is suggested that you do it like I said, on the guide: http://www.prototypejs.org/learn/extensions (at the bottom)
Pedro Cunha
+1  A: 

Are you loading this across SSL?

There is a known issue in IE where sometimes it fails to load XML over SSL:

http://support.microsoft.com/default.aspx?scid=kb;en-us;272359

This page contains more info on how to resolve it:

http://www.blog.lessrain.com/flash-nasty-xml-load-bug-in-internet-explorer/

Joeri Sebrechts
+1  A: 

Ensure that your in your headers that you're specifying the Content-Type and charset, and that your charset (if using utf-8) is utf-8 and not utf8. IE doesn't recognise the latter and doesn't bother to tell you.

So, you want your header to specify the following:

Content-Type: application/xml; charset=utf-8
digitala