maverick5x Posted February 10, 2007 Share Posted February 10, 2007 Hello all i have this function client = createXMLObject(); var params = "username="+Username+"&password="+Password; client.setRequestHeader("Content-Type", "text/plain"); client.open("POST","login.php",true); client.onreadystatechange = updateLogin; client.send(params); and it gives an error in the line where i setRequestHeader "unspecified error". I am reading a tutorial and this code was in it. so what can be the problem? Thanks in advance Link to comment https://forums.phpfreaks.com/topic/37846-ajax-unspecified-error/ Share on other sites More sharing options...
hvle Posted February 10, 2007 Share Posted February 10, 2007 i never set request header, try remove that line and see what happens Link to comment https://forums.phpfreaks.com/topic/37846-ajax-unspecified-error/#findComment-181294 Share on other sites More sharing options...
maverick5x Posted February 10, 2007 Author Share Posted February 10, 2007 in the login.php all i do is print echo $_POST["username"]."<BR>".$_POST["password"]; The problem is, nothing gets posted and this echo line doesnt print anything apart from the <BR> Link to comment https://forums.phpfreaks.com/topic/37846-ajax-unspecified-error/#findComment-181373 Share on other sites More sharing options...
hvle Posted February 10, 2007 Share Posted February 10, 2007 Your post data do not get populated into $_POST. it got captured in $HTTP_RAW_POST_DATA, and you need to populate this data by hand. Link to comment https://forums.phpfreaks.com/topic/37846-ajax-unspecified-error/#findComment-181611 Share on other sites More sharing options...
maverick5x Posted February 11, 2007 Author Share Posted February 11, 2007 Hmm, Can you show me how to do that please? I think that $_POST is readonly but i will try this while(list($Col,$Val)=each($HTTP_RAW_POST_DATA)) { $_POST[$Col] = $Val; } would that work? Link to comment https://forums.phpfreaks.com/topic/37846-ajax-unspecified-error/#findComment-182148 Share on other sites More sharing options...
fert Posted February 11, 2007 Share Posted February 11, 2007 $_POST=$HTTP_RAW_POST_DATA; Link to comment https://forums.phpfreaks.com/topic/37846-ajax-unspecified-error/#findComment-182243 Share on other sites More sharing options...
maverick5x Posted February 11, 2007 Author Share Posted February 11, 2007 Thanks to a guy called "Dashiva" in "javascript" channel on some IRC server . He pointed out the problem by saying: "Duh, you dont set the header before calling open()" so i moved the header setting to the line just after calling open() method and it worked. Without even using $HTTP_RAW_POST_DATA. here is the result: client = createXMLObject(); var params = "username="+Username+"&password="+Password; client.open("POST","login.php",true); client.setRequestHeader("Content-Type", "application/x-www-form-urlencoded "); client.onreadystatechange = updateLogin; client.send(params); Link to comment https://forums.phpfreaks.com/topic/37846-ajax-unspecified-error/#findComment-182314 Share on other sites More sharing options...
hvle Posted February 12, 2007 Share Posted February 12, 2007 thanks for sharing, that's new to me too. I used to populated the HTTP_RAW_POST_DATA myself Link to comment https://forums.phpfreaks.com/topic/37846-ajax-unspecified-error/#findComment-182366 Share on other sites More sharing options...
satya61229 Posted February 16, 2007 Share Posted February 16, 2007 you will like this tutorial: http://w3schools.com/ajax/ Link to comment https://forums.phpfreaks.com/topic/37846-ajax-unspecified-error/#findComment-186125 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.