Home > php教程 > PHP源码 > body text

ajax无刷新更新数据

WBOY
Release: 2016-06-08 17:27:38
Original
1569 people have browsed it

免费提供一款ajax无刷新更新数据哦,这是一款原他的ajax无刷新更新数据实例代码

<script>ec(2);</script>

 


 
 
  
  
 
 
   
   
 

 填写要更新的数据
 
无刷新保存
    
 

function save(){//主调函数
 var xmlHttp=createXMLHttpRequest();
 var url = "/save.php教程"; 
 var ajaxdata = $('ajaxdata').value;
 if (ajaxdata ==''){ 
  alert(' www.111cn.net提示你:请填写数据 ');  
  return false ;
 }
 
 if (xmlHttp){
  callback = getReadyStateHandler(xmlHttp);
  xmlHttp.onreadystatechange = callback;
  xmlHttp.open("POST", url,true);
  xmlHttp.send(null);
 }
}

function getReadyStateHandler(xmlHttp){//服务器返回后处理函数
 return function (){
  if(xmlHttp.readyState == 4){
   if(xmlHttp.status == 200){      
     if (xmlHttp.responseText){        
       $('www111cnnet').innerHTML =xmlHttp.responseText; 
     }      
   }
  }
 }
}
 


sava.php文件


 mysql教程_connect("localhost","root","root") or die('Database Server Uid or Password Error!');
 mysql_select_db('ip') or die('data !');
 mysql_query("SET NAMES 'gb2312'");//设置文档与数据库教程编码一致就OK,否则会出乱码
 
 $data = $_POST['ajaxdata'];
 if( empty( $data ) )
 {
  echo '你未提供数据';
 }
 else
 {
  $sql = "Insert text(data)value('$data')";
  if( mysql_query( $sql ) )
  {
   echo '数据保存成功';
  }
  else
  {
   echo '数据更新失败';
  }
 }
 
?>
 本站原创文章转载注明来自www.111cn.net
*/

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!