rows( $row ) ){echo 1;}else{return NULL"> 跳转到主内容
新派编程网 - 新潮编程理念,全新技术课堂!

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

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="对不起,你输入的标题存在重复哦!

";}else{document.getElementById("checkid").innerHTML="";}}}}}html代码这一句了,简单吧。

相关文章