Note that there are some explanatory texts on larger screens.

plurals
  1. PODifferent AJAX XML results from same PHP file with same POST parameters using JQuery
    primarykey
    data
    text
    <p>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.</p> <p>[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.</p> <p>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..</p> <p>Here are the code snippets:</p> <p>The JQuery ajax call (used in both the test file and within my project is):</p> <pre><code> $.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){ } }) </code></pre> <p>The PHP code is:</p> <pre><code>$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 .= "&lt;Friend&gt;"; $xml .= "&lt;ID&gt;$ID&lt;/ID&gt;"; $xml .= "&lt;Name&gt;$Name&lt;/Name&gt;"; $xml .= "&lt;Pic&gt;$pic_square&lt;/Pic&gt;"; $xml .= "&lt;/Friend&gt;"; } 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 "&lt;?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?&gt;"; echo "&lt;Friends&gt;"; echo $xml; echo "&lt;/Friends&gt;"; </code></pre> <p>Note: I tried changing the headers to force a full refresh, but it still didn't help</p> <p><strong>Test File</strong> The headers from Firebug of the test PHP file (which returns the correct results are):</p> <pre><code>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 </code></pre> <p>And the Response is:</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8" standalone="yes"?&gt;&lt;Friends&gt;&lt;Friend&gt;&lt;ID&gt;12&lt;/ID&gt;&lt;Name&gt;XXX &lt;/Name&gt;&lt;Pic&gt;http://something&lt;/Pic&gt;&lt;/Friend&gt;&lt;/Friends&gt; </code></pre> <p><strong>Main Project</strong> The Firebug headers from the ajax call from my main project are:</p> <pre><code>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 </code></pre> <p>And the response is:</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8" standalone="yes"?&gt;&lt;Friends&gt;&lt;/Friends&gt; </code></pre> <p>So for some reason, the inner XML node is being omitted from the results when called from the main project.</p> <p>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!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload