| ResponseText Empty :( TWO DAYS wasted
|
iamvela

msg:4079466 | 2:16 am on Feb 13, 2010 (gmt 0) | I am doing what-should-have-been-a-very-simple hello-world AJAX application that talks to my server. I am testing with Firebug. My JS code successfully makes the connection to my server script. Server script inserts a row into DB. No Problem. Firebug gives back status 200. No Problem Firebug shows the right content-length e.g. 3 No Problem. Even the size is 3. No Problem. If I echo hello, then it is 5. No Problem. A version of my server PHP is as simple as <?php echo 'end' ; ?> The problem is that the data (e.g. the string 'end') never appears in my responseText. Not even in Firebug. I've put the server on sleep for before replying, I've put a delay in the JS code before checking for 200 status, and a few other things... I AM STUMPED. Please help... ANYONE? This is driving me crazy... BTW for some reason, the same code stops working if I use POST (I do have a line as oXmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded') ; for the POST)
|
Fotiman

msg:4081010 | 4:01 am on Feb 16, 2010 (gmt 0) | Could you post the relevant AJAX portion of code? My initial thought is are you checking for readyState == 4?
|
iamvela

msg:4081372 | 4:48 pm on Feb 16, 2010 (gmt 0) | That is correct, is that not what I am supposed to do? :(
|
Fotiman

msg:4081411 | 5:23 pm on Feb 16, 2010 (gmt 0) | Yes, you should be checking for readyState == 4. I just wanted to make sure you were doing that. Could you post a bit of your AJAX code?
|
iamvela

msg:4081583 | 8:51 pm on Feb 16, 2010 (gmt 0) | Here's my JS code:
function createXMLHttp() { if (typeof XMLHttpRequest != "undefined") { return new XMLHttpRequest(); } else if (window.ActiveXObject) { var aVersions = ["MSXML2.XMLHttp.5.0", "MSXML2.XMLHttp.4.0", "MSXML2.XMLHttp.3.0", "MSXML2.XMLHttp", "Microsoft.XMLHttp"]; for (var i = 0; i < aVersions.length; i ++ ) { try { var oXmlHttp = new ActiveXObject(aVersions[i]); return oXmlHttp; } catch (oError) {} // Do nothing } } throw new Error("XMLHttp object could be created."); }
function do_post(url, data, suc) { var oXmlHttp = createXMLHttp(); var method_ = ""; if(data == "" || data == null) method_ = "get"; else method_ = "post"; //alert(method_ + url) ; oXmlHttp.open(method_, url , true); oXmlHttp.onreadystatechange = function () { if (oXmlHttp.readyState == 4) { alert (oXmlHttp.status) ; if (oXmlHttp.status == 200) { var response ; response = oXmlHttp.responseText; var transport = new Object; transport.responseText = response; suc(transport); } } } ; // if (data != "" || data != null) oXmlHttp.overrideMimeType('text/html'); //if (data != "" || data != null) oXmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); if (data == "" || data == null) // Lets use GET method { oXmlHttp.send(null); } else // Lets POST the data { oXmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded') ; oXmlHttp.send(data); } }
function myRspHandler(transport) { alert ('handler') ; var responseText = transport.responseText; eval (responseText); }
Here's my PHP code:
<?php include_once 'myChkBrowser.php' ; include_once("database_info.php");
mysql_query("INSERT into test (`debug_msg`) VALUES ('" . $browserVer .": " . $_REQUEST['text'] . ": I made the AJAX call from WP plugin')" ) ;
//echo '<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<begin' ; //echo 'end>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>' ;
?>
|
Fotiman

msg:4081594 | 9:16 pm on Feb 16, 2010 (gmt 0) | var aVersions = ["MSXML2.XMLHttp.5.0", "MSXML2.XMLHttp.4.0", "MSXML2.XMLHttp.3.0", "MSXML2.XMLHttp", "Microsoft.XMLHttp"]; |
| Ack! That is definitely not good. MSXML 5.0 and 4.0 are not recommended by Microsoft. Check out Cross Browser XMLHttpRequest Explained [webmasterworld.com]. I would start by correcting this first. You'll want to use either MSXML 6.0 or MSXML 3.0. Next, it looks like your PHP code is not outputting anything.
|
iamvela

msg:4081603 | 9:31 pm on Feb 16, 2010 (gmt 0) | PHP code is outputting, just a matter of where in the debug cycle I was, and thanks for cacthing the MSXML...
|
|
|