Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.