Mr.47 Posted January 16, 2010 Share Posted January 16, 2010 hi guys..im a new member nd m also new to ajax/php. iam trying to update my database through ajax technique. problem is dat parameters to update.php file are not passing. while alerting them in js file shows it correct. here is some code for better understanding.. <a onclick="updatedata(<?php echo $id; ?>)" href="#"><img src="images/save.png"></a> update.js file: // JavaScript Documentvar xmlhttp function updatedata(id) { var xmlhttp xmlhttp= GetXmlHttpObject() if(xmlhttp==null) { alert("browser does not support HTTP request") return } xmlhttp.onreadystatechange= function() { if(xmlhttp.readystate==4) { var updt= document.getElementById("mydata"); updt.value=xmlhttp.responseText; } } var str= document.getElementById("mydata").value; var url="insert.php?id=" + id + "&data=" + str; xmlhttp.open("GET",url,true); xmlhttp.send(null); } function GetXmlHttpObject() { if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari return new XMLHttpRequest(); } if (window.ActiveXObject) { // code for IE6, IE5 return new ActiveXObject("Microsoft.XMLHTTP"); } return null; } insert.php file: <?php $id=$_GET["id"]; $data=$_GET["data"]; $conn= mysql_connect("localhost", "root", ""); if(!$conn) { die("connection failed!" . mysql_error()); } mysql_select_db("backend", $conn); $query = "UPDATE myfirst SET description ='$data' WHERE id='$id'"; mysql_query($query); ?> kindly show me how can i pass the param id and the edited data(str) to the php update file? Quote Link to comment Share on other sites More sharing options...
jl5501 Posted January 24, 2010 Share Posted January 24, 2010 As far as I can see, you are correctly passing the data to the insert.php, but as you may not wish to see the result, you have not coded a callback onreadystatechange. It may be useful to include a callback function where you can simply alert the responseText, so you can at least see what insert.php is outputting, and you could then add some debug output to insert.php to further help with debugging. If you do not need the callback in the finished application, you could always remove it when you have it working. 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.