Different AJAX XML results from same PHP file with same POST parameters using JQuery

I'm using the JQuery .ajax method to get the results of a simple PHP query in XML (which I've done various times within this project without a problem). However, the XML result that I receive from within my main project is different to what I expect (as tested by simply viewing the PHP file) when viewing the results in Firebug's console. I also tested this again by creating a new PHP file whose sole function is to run the ajax call and the results are correct, as expected. [Update]: I just tested this out again, and I received the correct results from within my project, but when I refresh the page, I get the incorrect results again. For the sake of testing, I simplified the process by removing all POST data and the success callback function, but I still get different results.. Here are the code snippets: The JQuery ajax call (used in both the test file and within my project is): $.ajax({ url:"./lib/ajax_friends.php", type:"POST", // data:{action : "getFriends", userID: userID} , dataType: 'xml', sync:false, error:function(request){alert("error")}, success:function(theXML){ } }) The PHP code is: $userID='11'; $sql = "SELECT ID, name, pic_square FROM users WHERE ID = $userID"; $result = mysql_query($sql) or die(mysql_error()); $xml = ""; while($array = mysql_fetch_array($result)) { $ID = $array['ID']; $Name = $array['name']; $pic_square = $array['pic_square']; $xml .= ""; $xml .= "$ID"; $xml .= "$Name"; $xml .= "$pic_square"; $xml .= ""; } header('Content-Type: application/xml; charset=ISO-8859-1'); header("Cache-Control: no-cache, must-revalidate"); header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); echo ""; echo ""; echo $xml; echo ""; Note: I tried changing the headers to force a full refresh, but it still didn't help **Test File** The headers from Firebug of the test PHP file (which returns the correct results are): Response Headers Date Fri, 08 May 2009 18:53:34 GMT Server Apache/2.2.9 (Unix) mod_ssl/2.2.9 OpenSSL/0.9.7l DAV/2 PHP/5.2.6 X-Powered-By PHP/5.2.6 Cache-Control no-cache, must-revalidate Expires Mon, 26 Jul 1997 05:00:00 GMT Content-Length 200 Keep-Alive timeout=5, max=98 Connection Keep-Alive Content-Type application/xml; charset=ISO-8859-1 Request Headers Host localhost User-Agent Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.0.10) Gecko/2009042315 Firefox/3.0.10 Accept application/xml, text/xml, */* Accept-Language en-us,en;q=0.5 Accept-Encoding gzip,deflate Accept-Charset ISO-8859-1,utf-8;q=0.7,*;q=0.7 Keep-Alive 300 Connection keep-alive X-Requested-With XMLHttpRequest Referer http://localhost/~Seeff/testajax.php Cookie a7c768c2549daf4a7f69b9916bab5a38=4555bf36cf1b308f19a12f8da6944b80; a7c768c2549daf4a7f69b9916bab5a38_user =507514167; a7c768c2549daf4a7f69b9916bab5a38_ss=kKgqsUlOrFArzo9Nrv2Zyg__; a7c768c2549daf4a7f69b9916bab5a38_session_key =3.qPXakpbNIIX_bvndm_5gnA__.86400.1241895600-507514167; a7c768c2549daf4a7f69b9916bab5a38_expires=1241895600 ; fbsetting_a7c768c2549daf4a7f69b9916bab5a38=%7B%22connectState%22%3A1%2C%22oneLineStorySetting%22%3A1 %2C%22shortStorySetting%22%3A1%2C%22inFacebook%22%3Afalse%7D And the Response is: 12XXX http://something **Main Project** The Firebug headers from the ajax call from my main project are: Response Headers Date Fri, 08 May 2009 18:53:41 GMT Server Apache/2.2.9 (Unix) mod_ssl/2.2.9 OpenSSL/0.9.7l DAV/2 PHP/5.2.6 X-Powered-By PHP/5.2.6 Cache-Control no-cache, must-revalidate Expires Mon, 26 Jul 1997 05:00:00 GMT Content-Length 74 Keep-Alive timeout=5, max=98 Connection Keep-Alive Content-Type application/xml; charset=ISO-8859-1 Request Headers Host localhost User-Agent Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.0.10) Gecko/2009042315 Firefox/3.0.10 Accept application/xml, text/xml, */* Accept-Language en-us,en;q=0.5 Accept-Encoding gzip,deflate Accept-Charset ISO-8859-1,utf-8;q=0.7,*;q=0.7 Keep-Alive 300 Connection keep-alive X-Requested-With XMLHttpRequest Referer http://localhost/~Seeff/ Cookie a7c768c2549daf4a7f69b9916bab5a38=4555bf36cf1b308f19a12f8da6944b80; a7c768c2549daf4a7f69b9916bab5a38_user =507514167; a7c768c2549daf4a7f69b9916bab5a38_ss=kKgqsUlOrFArzo9Nrv2Zyg__; a7c768c2549daf4a7f69b9916bab5a38_session_key =3.qPXakpbNIIX_bvndm_5gnA__.86400.1241895600-507514167; a7c768c2549daf4a7f69b9916bab5a38_expires=124 1895600 And the response is: So for some reason, the inner XML node is being omitted from the results when called from the main project. I'm guessing that there's something in my main project that must be interfering in some way, but I just can't figure it out. Any help is greatly appreciated!

以上就是Different AJAX XML results from same PHP file with same POST parameters using JQuery的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » jQuery 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准

联系我们

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏