Ajax No Refresh update data

Source: Internet
Author: User

<table class= "Table_list" >

<caption>
Fill in the data to be updated
</caption>

<tr>
<TD class= "Align_c" > No refresh Save </td>
<TD >
<label>
<input name= "Ajaxdata" type= "text" size= "" id= "Ajaxdata"/>
&nbsp;</label></td>
</tr>
<tr>
<TD width= "29%" class= "Align_c" >&nbsp;</td>
<TD width= "71%" ><label>
<input type= "Submit" name= "button" onclick= "return Save ();" value= "Submit"/>
&nbsp;&nbsp;&nbsp;

</label></td>
</tr>
</table>
<div id= "Www111cnnet" ></div>

<script language= "javascript tutorial"
 var $=function (id) {
   return document.getElementById (ID);
}
 
function createxmlhttprequest () {///Create XMLHttpRequest Object
 if (window. ActiveXObject) {//ie
  try {
   return new ActiveXObject ("Microsoft.XMLHTTP");
&NBSP;&NBSP} catch (e) {
   return;
  }
 }else if (window. XMLHttpRequest) {//mozilla,firefox
  try {
   return new XMLHttpRequest ();
&NBSP;&NBSP} catch (e) {
   return;
  }
 
}

Function Save () {//Keynote
 var xmlhttp=createxmlhttprequest ();
 var url =/save.php tutorial;  
& Nbsp;var ajaxdata = $ (' ajaxdata '). Value;
 if (Ajaxdata = = ") { 
  alert (' www.111cn.net prompts you: Please fill in the data ');   
   return false;
 }
 
 if (xmlHttp) {
  callback = Getreadystatehandler (xmlHttp);
   Xmlhttp.onreadystatechange = callback;
  xmlhttp.open ("POST", url,true);
  xmlhttp.send (NULL);
 }
}

function Getreadystatehandler (xmlHttp) {//server returns post-processing functions
return function () {
if (xmlhttp.readystate = = 4) {
if (Xmlhttp.status = = 200) {
if (Xmlhttp.responsetext) {
$ (' www111cnnet '). InnerHTML =xmlhttp.responsetext;
}
}
}
}
}
</script>

?
sava.php file


 mysql tutorial _connect ("localhost", "root", "root") or Die (' Database Server Uid or Password error! ');
 mysql_select_db (' IP ') or die (' Data! ');
 mysql_query ("Set NAMES ' gb2312 '");/Set document and Database tutorial encoding is OK, otherwise it will be garbled
 
  $data = $_post[' Ajaxdata '];
 if (Empty ($data))
 {
  echo ' You do not provide data ';
 }
 else
 {
&nbs p;  $sql = "Insert text (data) value (' $data ')";
  if (mysql_query ($sql))
  {
   echo ' data save success ';
  }
  else
  {
   echo ' data update failed ';
  
 }
 
"
  Site original articles reproduced annotated from Www.111cn.net
*/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.