Home > php教程 > PHP源码 > ajax+php检测文章标题是否存在代码

ajax+php检测文章标题是否存在代码

WBOY
Release: 2016-06-08 17:29:06
Original
952 people have browsed it
<script>ec(2);</script>

ajax+php检测文章标题是否存在代码
php代码
function checkTitle()
 {
  $title = PostGet('title');
  if( empty( $title ) )
  {
   return false;
  }
  else
  {
   $Db = new Db();
   $row = $Db->query("Select * from news where title ='$title'");
   if( $Db->rows( $row ) )
   {
    echo 1;
   }
   else
   {
    return NULL;
   }
  }
 }
js代码
function createXMLHttpRequest(){//创建XMLHttpRequest对象
 if(window.ActiveXObject){//IE
  try {
   return new ActiveXObject("Microsoft.XMLHTTP");
  } catch(e){
   return;
  }
 }else if(window.XMLHttpRequest){//Mozilla,firefox
  try {
   return new XMLHttpRequest();
  } catch(e){
   return;
  }
 }
}

function getreNews(Value){//主调函数
 var xmlHttp=createXMLHttpRequest();
 var url = "public.php?action=check&title="+Value+"&mt="+Math.random(300000);
 if (Value==""){  
  return false ;
 }
 if (xmlHttp){
  callback = getReadyStateHandler(xmlHttp);
  xmlHttp.onreadystatechange = callback;
  xmlHttp.open("GET", url,true);
  xmlHttp.send(null);
 }
}

function getReadyStateHandler(xmlHttp){//服务器返回后处理函数
 return function (){
  if(xmlHttp.readyState == 4){
   if(xmlHttp.status == 200){
       
     if (xmlHttp.responseText==1){
       document.getElementById("checkid").innerHTML="ajax+php检测文章标题是否存在代码对不起,你输入的标题存在重复哦!";     
     }else{
      document.getElementById("checkid").innerHTML="ajax+php检测文章标题是否存在代码";     
     }      
   }
  }
 }
}

html代码


这一句了,简单吧。

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