garethhall Posted October 23, 2009 Share Posted October 23, 2009 Hey Guys, I am stuffed if I know what is causing this page not to work I have now spend I don't know how many hours on it. Please have a look and see if you can see what is wrong? I keep on getting the "BAD" alert? but when I alert(xmlHttp.responseText) I get "ok" then how how come it is alerting "BAD" should it not be "GOOD"? Initial PHP page code libEdtBook.php <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <script type="text/javascript" src="ajax/js/edtBook.js"></script> </head> <body> <form name="frmAddBook" method="post"> <input type="button" name="updateTheBook" id="updateTheBook" value="Update book details" onclick="svBook()"/> </form> </body> </html> JS ajax code edtBook.js var xmlHttp function svBook(){ xmlHttp=GetXmlHttpObject() if(xmlHttp==null){ alert("Browser does not support HTTP Request"); return; } var qstr; xmlHttp.onreadystatechange = bookSaveResult; xmlHttp.open("POST","ajax/edtBook.php?",true); xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); xmlHttp.send(qstr); } function bookSaveResult(){ if(xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){ if(xmlHttp.responseText == "ok"){ alert("GOOD"); }else { alert("BAD"); } } } function GetXmlHttpObject(){ var xmlHttp=null; try{ // Firefox, Opera 8.0+, Safari xmlHttp=new XMLHttpRequest(); }catch (e){ // Internet Explorer try{ xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); }catch (e){ xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); } } return xmlHttp;} PHP page Ajax is calling edtBook.php <?php echo "ok" ?> Link to comment https://forums.phpfreaks.com/topic/178707-solved-i-am-baffled-as-to-why-this-is-not-working/ Share on other sites More sharing options...
Gayner Posted October 23, 2009 Share Posted October 23, 2009 Remove the ? from editbook.php and see. Link to comment https://forums.phpfreaks.com/topic/178707-solved-i-am-baffled-as-to-why-this-is-not-working/#findComment-942686 Share on other sites More sharing options...
dreamlove Posted October 23, 2009 Share Posted October 23, 2009 try to find blank or \n or tab in your php file. try to alert(xmlHttp.responseText) and alert(xmlHttp.responseText.length) and add cache control in your php file. Link to comment https://forums.phpfreaks.com/topic/178707-solved-i-am-baffled-as-to-why-this-is-not-working/#findComment-942687 Share on other sites More sharing options...
garethhall Posted October 23, 2009 Author Share Posted October 23, 2009 Thanks guys so simple there was a space in the php Link to comment https://forums.phpfreaks.com/topic/178707-solved-i-am-baffled-as-to-why-this-is-not-working/#findComment-942695 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.