homepage Welcome to WebmasterWorld Guest from 54.196.63.93
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

    
ResponseText Empty :( TWO DAYS wasted
iamvela

5+ Year Member



 
Msg#: 4079464 posted 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

WebmasterWorld Senior Member fotiman us a WebmasterWorld Top Contributor of All Time 5+ Year Member



 
Msg#: 4079464 posted 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

5+ Year Member



 
Msg#: 4079464 posted 4:48 pm on Feb 16, 2010 (gmt 0)

That is correct, is that not what I am supposed to do? :(

Fotiman

WebmasterWorld Senior Member fotiman us a WebmasterWorld Top Contributor of All Time 5+ Year Member



 
Msg#: 4079464 posted 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

5+ Year Member



 
Msg#: 4079464 posted 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

WebmasterWorld Senior Member fotiman us a WebmasterWorld Top Contributor of All Time 5+ Year Member



 
Msg#: 4079464 posted 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

5+ Year Member



 
Msg#: 4079464 posted 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...

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved