Jump to content

INSERT records using AJAX


robert_gsfame

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/220307-insert-records-using-ajax/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.