简体   繁体   中英

Ajax/jQuery/PHP in IE9 but not IE 8 or less

My jQuery/AJAX script posts to a php file in hopes of returning XML. When I print if the data I get all the html source code returned and the xml is not properly parsed in IE 8 or less. The code works in IE 9 and all other browsers. If anyone has a suggesion to what is goin on or a solution to my problem?

jQuery:

$.post("load-content/", {type: "POST", img: placeholder, dataType: "XML", selection: $(this).html()}, function(xml)  {
                // format and output result
                // alert(placeholder+' && '+$(this).html());
                nshow = $("content", xml).text() ;
                $("div p.p2").html(
                    $("content", xml).text() 
                );
                alert("HERE IE 9+ "+xml.length);
            });

php:

if(isset($_REQUEST["img"]) && isset($_REQUEST["selection"])) {
      $xml='<ratings><content>test</content></ratings>';
      echo $xml;

*FYI this code is being run in Zencart folder

Solved.
There were two problems here.

  1. As the above answer suggested there was a problem with headers.
  2. Again as the answer above suggested there was a problem with the datatype... code for older IE browsers should look something like

     $.post("/load-content/", {type: "POST", img: showcase, menuv: aname}, function(response) { ... 

Actually i think your problem is making the ajax call itself. You are using $.post but youre supplying the options hash as if it is $.ajax . The two are different...

$.post takes the url, data, callback and response type as the arguments. You are supplying a hash similar to the one you would supply to $.ajax as your second argument which is not what it wants.

If you are going to use $.post it shoudl look like this:

$.post("load-content/", {img: placeholder, selction: whatever}, function(), 'xml');

Additionally its not obivous what the contex of your call is... this may not exist unless this is inside an event handler or jQuery.each iteration so using selection: $(this).html() may not make sense.


Have you tried setting the proper header for your response and exiting immeadiately?

 if(isset($_REQUEST["img"]) && isset($_REQUEST["selection"])) {
      header('Content-type: application/xml');
      $xml='<ratings><content>test</content></ratings>';
      echo $xml;
      exit(0);
 }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM