开发者

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

开发者 https://www.devze.com 2023-02-22 07:28 出处:网络
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 i

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);
 }
0

精彩评论

暂无评论...
验证码 换一张
取 消