robert_gsfame Posted December 1, 2010 Share Posted December 1, 2010 hi, i am new to AJAX and i have problems when cope with query. How can i insert a record into database <script type="text/javascript"> function addcontact(str) { if (window.XMLHttpRequest) { xmlhttp=new XMLHttpRequest(); } else { xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.open("GET","page2.php?id="+str); xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { document.getElementById("ajaxpage").innerHTML=xmlhttp.responseText; }else{ document.getElementById("ajaxpage").innerHTML="<img src=loading.gif>";} } xmlhttp.send(); } </script> here is the html code <a href=javascript:void(0) onclick=addcontact('123')>add Contact</a> i wish to pass the value of 123 using $_GET to page2.php. in page2.php, it will execute the INSERT query and change the <a href=javascript:void(0) onclick=addcontact('123')>add Contact</a> into "Your contact has been added successfully" thx Quote Link to comment https://forums.phpfreaks.com/topic/220307-insert-records-using-ajax/ 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.