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 Quote Link to comment 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 Quote Link to comment 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> Quote Link to comment 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. Quote Link to comment 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? Quote Link to comment Share on other sites More sharing options...
fert Posted February 11, 2007 Share Posted February 11, 2007 $_POST=$HTTP_RAW_POST_DATA; Quote Link to comment 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); Quote Link to comment 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 Quote Link to comment 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/ Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.