这篇文章主要介绍了PHP+Ajax实现的博客文章添加类别功能,结合实例形式分析了php+ajax实现的数据交互、数据库连接、查询等相关操作技巧,需要的朋友可以参考下
本文实例讲述了PHP+Ajax实现的博客文章添加类别功能。分享给大家供大家参考,具体如下:
一. 代码
fun.js
function saveType(typename,<strong style="color:transparent">来源gao@daima#com搞(%代@#码网</strong> username){ if(typename==''){ //判断博客类别是否为空 alert('请输入类别名称!'); }else if(username==''){ //判断用户名是否为空 alert('请输入用户名!'); }else{ var xmlObj; //定义XMLHttpRequest对象 var urlData = "typename="+typename+"&username="+username; //指定要发送的数据 if(window.ActiveXObject){ //判断浏览器是否支持ActiveXObject组件,如支持则通过ActiveXObject方式创建XMLHttpRequest对象 xmlObj = new ActiveXObject("Microsoft.XMLHTTP"); }else if(window.XMLHttpRequest){ //如果浏览器不支持ActiveXObject组件,则使用XMLHttpRequest组件创建XMLHttpRequest对象 xmlObj = new XMLHttpRequest(); } xmlObj.onreadystatechange = callBackFun; //指定回调函数 xmlObj.open("POST", "saveType.php", true); //指定提交方法和页面 xmlObj.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;"); //指定发送数据库类型 xmlObj.send(urlData); //指定发送的数据 function callBackFun(){ //定义回调函数 if(xmlObj.readyState == 4 && xmlObj.status == 200){ //如果服务器端返回内容并无错误发生 if(xmlObj.responseText == 'y'){ //判断保存是否成功,并给出提示 alert('类别添加成功!'); }else{ alert('类别添加失败!'); } } } } }
conn.php
index.php
<title>添加类别</title> <table border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td></td></tr></table><table width="200" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td></td></tr></table><table width="608" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#7ED227"> <tr> <td width="150" bgcolor="#F6FEFE" valign="top"> <table width="150" border="0" cellpadding="0" cellspacing="1" bgcolor="#D6FEFE"> <tr> <td bgcolor="#A6E617" height="20"><div align="center"></div></td></tr><tr> <td bgcolor="#F2F2F2" height="12"><div align="left">发布人: </div></td></tr> <tr> <td bgcolor="#A6E617" height="20">暂无文章类别</td></tr> </table></td><td width="455" bgcolor="#FFFFFF" style="padding-left:30px;line-height:25px"> 请输入博客类别:<br /> <br /><br /> 发布人:<br /> <br /><br /></td></tr></table><table width="200" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td></td></tr></table><table width="608" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td><div align="center"> <div align="center">『博客』 版权所有 吉林省**科技有限公司! 未经授权禁止复制或建立镜像!<br><br>Copyright © www.mingri***.com All Rights Reserved!<br></div></div></td></tr></table>
saveType.php
<title>添加类别</title> <table border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td></td></tr></table><table width="200" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td></td></tr></table><table width="608" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#7ED227"> <tr> <td width="150" bgcolor="#F6FEFE" valign="top"> <table width="150" border="0" cellpadding="0" cellspacing="1" bgcolor="#D6FEFE"> <tr> <td bgcolor="#A6E617" height="20"><div align="center"></div></td></tr><tr> <td bgcolor="#F2F2F2" height="12"><div align="left">发布人: </div></td></tr> <tr> <td bgcolor="#A6E617" height="20">暂无文章类别</td></tr> </table></td><td width="455" bgcolor="#FFFFFF" style="padding-left:30px;line-height:25px"> 请输入博客类别:<br /> <br /><br /> 发布人:<br /> <br /><br /></td></tr></table><table width="200" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td></td></tr></table><table width="608" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td><div align="center"> <div align="center">『博客』 版权所有 吉林省**科技有限公司! 未经授权禁止复制或建立镜像!<br><br>Copyright © www.mingri***.com All Rights Reserved!<br></div></div></td></tr></table>
二. 运行结果
更多关于PHP相关内容感兴趣的读者可查看本站专题:《PHP+ajax技巧与应用小结》、《PHP网络编程技巧总结》、《PHP基本语法入门教程》、《php面向对象程序设计入门教程》、《php字符串(string)用法总结》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总》
希望本文所述对大家PHP程序设计有所帮助。
以上就是PHP+Ajax实现的博客文章添加类别功能示例的详细内容,更多请关注gaodaima搞代码网其它相关文章!