views:

38

answers:

2

Hi guys, i hope you can help me with this one. The code is supposed to display mysql data using a php script returning XML (the backend script works fine delivering good XML - checked with my previous question on Stack Overflow).

I'm using jQuery 1.4.2 to do a .get AJAX call - and i just can't get Internet Explorer to display even a bit. Chrome, Safari, Chromium, FireFox and Opera work just fine here - i wonder what i did wrong ?

I checked the problem about IE and jQuery and i found this piece of code that could help but it doesn't work :

 function parseXml(xml)
  { 
    if (jQuery.browser.msie)

      {
        var xmlDoc = new ActiveXObject("Microsoft.XMLDOM"); 
        xmlDoc.loadXML(xml);
        xml = xmlDoc;
      }

    return xml;
  }

Is there anything i can do to display my posts in Internet Explorer?

I put an "alert" at the beginning of the xml parsing function but Internet Explorer never gets there to display alert. Other browsers do. It seems it doesn't even execute the

`function(xml) { bazinga_getposts(xml); }` 

from jQuery .GET

Thanks for any idea! The IE version is 8

Here is the full code:

var ajax_content_left=$("#ajax_content_left");
var ajax_content_left_pagination=$('#ajax_content_left_pagination');

function parseXml(xml)

    {   
        if (jQuery.browser.msie)
            {
                var xmlDoc = new ActiveXObject("Microsoft.XMLDOM"); 
                xmlDoc.loadXML(xml);
                xml = xmlDoc;
            }

        return xml;
    }


$.get("bazinga_blob/getposts.php",

    { 

        category:"1", 
        post_tags:"", 
        language:"pl", 
        author:"1", 
        posts_per_page:"2", 
        current_page:"1", 
        order:"desc", 
        hard_limit:"", 
        show_hidden:"1" 

    }, function(xml) { bazinga_getposts(xml); },'xml'); 



function bazinga_getposts(xml) 

    {   

        alert('found it');

        thexml=$(xml);
        thexml=parseXml(thexml);

        var fill_this='';
        var fill_pagination='';
        var ile_stron=thexml.find('LastPage').text();

        thexml.find('Post').each(function()

            {

                fill_this+='<h1>'+thexml.find('PostTitle').text()+'</h1>';
                fill_this+='<article>'+thexml.find('PostBody').text()+'</article>';

            });


        for (i=1;i<=ile_stron;i++)

            {

                fill_pagination+='<li><a href="#'+i+'">'+i+'</a></li>';     

            }



        ajax_content_left.append(fill_this);
        ajax_content_left_pagination.append(fill_pagination);       

    }
A: 

Maybe the returned content is invalid XML; see if it works with plain text. Also, try setting an error callback. If all else fails, you can try to debug it via Microsoft Script Editor.

Tgr
thanks Tgr, when i switch it to plain text - the function executes also in Internet Explorer but hooping through the each.find(' ')... doesn't return anything . The XML validates here: http://www.w3schools.com/dom/dom_validate.asp . In the php file i tried using these content-type headers: application/xml , application/xhtml+xml and text/html
Greg
A: 

Discovered!

Thanks for help, i started digging the php script again and i found here: http://articles.sitepoint.com/article/ajax-jquery/2 a line that was missing: it was the:

header("Cache-Control: no-cache");

that was necessary to start displaying stuff in Internet Explorer

See you :)

Greg
Withour a nocache header, IE might use the browser cache instead of actually doing the query. Personally, I wouldn't trust it to behave correctly even with the header specified - it is safer to break caching by appending some random string to the query. jQuery takes care of that if you set [the cache parameter](http://api.jquery.com/jQuery.ajax/) to false.
Tgr