php - Ajax function only works once -
i'm calling ajax function updates input form text value mysql database, works fine first time phone call ajax function if phone call 1 time again nil get's updated.
html , javascript:
<html> <head> <script type="text/javascript"> function updatetitle() { if (window.xmlhttprequest) {// code ie7+, firefox, chrome, opera, safari xmlhttp=new xmlhttprequest(); } else {// code ie6, ie5 xmlhttp=new activexobject("microsoft.xmlhttp"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readystate==4 && xmlhttp.status==200) { document.getelementbyid("txthint").innerhtml=xmlhttp.responsetext; } } var otsikko = document.getelementbyid('otsikko').value; xmlhttp.open("post","gettable.php",true); xmlhttp.setrequestheader("content-type","application/x-www-form-urlencoded"); xmlhttp.setrequestheader("if-modified-since", "sat, 1 jan 2000 00:00:00 gmt"); xmlhttp.send('otsikko=' + otsikko); } </script> </head> <body> <form name="test" action="javascript:updatetitle()" method="post"> <input type="text" id="otsikko" value="pagetitle"> <input type="submit" value="update"> </form> <div id="txthint"></div> </body> </html>
php:
$otsikko=$_post["otsikko"]; $con=mysql_connect('localhost', 'admin', 'password'); if (!$con) { die('could not connect: ' . mysql_error()); } mysql_select_db("database", $con); mysql_query("update site_content set pagetitle='$otsikko' longtitle='jee'"); echo "updated!"; echo $otsikko; mysql_close($con);
php javascript mysql ajax
No comments:
Post a Comment