function checkbiaoti(){
if(empty($_POST['biaoti'])){
echo'<font color=red>标题不能为空!</font>';
}
else{
};
}
function checkcontents(){
if(empty($_POST['contents'])||strlen($_POST['contents'])<60){
echo'<font color=red>内容为不能空或没有20字!</font>';
}
else{
};
}
function checksubmit(){
$user=M('members');
$comment=M('message');
$data['contents']=$_POST['contents'];
$data['biaoti']=$_POST['biaoti'];
$where['user_name']=$_SESSION['user_name'];
$res=$user->field('user_id')->where($where)->find();
$map['user_id']=$res['user_id'];
if($data!=''){
$rs=$comment->where($map)->add($data);
if($rs){
echo"<font color=green>发布信息成功!</font>";
}
else{
echo"<font color=red>发布信息失败!</font>";}
}
else{
echo"<font color=red>发布信息失败!</font>";}
}这是我的js代码ajax:// JavaScript Document
var XHR; //定义一个全局对象
function createXHR(){ //首先我们得创建一个XMLHttpRequest对象
if(window.ActiveXObject){//IE的低版本系类
XHR=new ActiveXObject('Microsoft.XMLHTTP');//之前IE垄断了整个浏览器市场,没遵循W3C标准,所以就有了这句代码。。。但IE6之后开始有所改观
}else if(window.XMLHttpRequest){//非IE系列的浏览器,但包括IE7 IE8
XHR=new XMLHttpRequest();
}
}
function checkbiaoti(){
var biaoti=document.myform.biaoti.value;
//alert(biaoti);
createXHR();
XHR.open("GET",".././Index/checkbiaoti?id="+biaoti,true);//true:表示异步传输,而不等send()方法返回结果,这正是ajax的核心思想
XHR.onreadystatechange=th;//当状态改变时,调用byhongfei这个方法,方法的内容我们另外定义
XHR.send(null);
}
function checkcontents(){
var contents=document.myform.contents.value;
createXHR();
//alert(contents);
XHR.open("GET",".././Index/checkcontents?cid="+contents,true);
XHR.onreadystatechange=th1;
XHR.send(null);
}
function th1(){
if(XHR.readyState==4){
if(XHR.status==200){
var textHTML=XHR.responseText;
document.getElementById('check2').innerHTML=textHTML;
}}
}
function th(){
if(XHR.readyState == 4){//关于Ajax引擎对象中的方法和属性,可以参考我的另一篇博文:http://www.cnblogs.com/hongfei/archive/2011/11/29/2265377.html
if(XHR.status == 200){
var textHTML=XHR.responseText;
document.getElementById('check1').innerHTML=textHTML;
}
}
}
function wc(){
var biaoti=document.myform.biaoti.value;
var contents=document.myform.contents.value;
var postStr = "biaoti="+biaoti +"&contents="+ contents;
createXHR();
//alert(biaoti);
//alert(contents);
var url=".././Index/checksubmit";
XHR.open("POST",url,true);
XHR.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
XHR.onreadystatechange=th3;
XHR.send(postStr);
}
function th3(){
if(XHR.readyState==4){
if(XHR.status==200){
var textHTML=XHR.responseText;
document.getElementById('check2').innerHTML=textHTML;
}
}
}这是我的网页代码:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="__ROOT__/Public/css/fb.css" rel="stylesheet" type="text/css">
<script language="JavaScript" src="../images/js/jquery-1.10.1.min.js" type="text/javascript"></script>
<script type="text/javascript" src="../images/js/ajaxreg.js"></script>
<title>发布策略</title>
<style type="text/css">
body,td,th {
font-size: 12px;
color: #000;
text-align: right;
}
body {
background-color: #EAF0FE;
margin: 0px;
}
.wenzi {
}
.wenzi {
text-align: center;
}
.wenzi {
text-align: left;
}
.zhong {
text-align: center;
}
.zi {
font-family: "宋体";
font-size: 14px;
color: #000;
font-weight: bold;
}
.di {
color: #666;
}
.shouyi {
font-family: "宋体";
font-size: 12px;
color: #576ED6;
text-align: center;
}
.tui {
font-family: "宋体";
font-size: 12px;
color: #FF0000;
}
.kuang {
border-bottom-width: thin;
border-bottom-style: dashed;
border-bottom-color: #ccc;
text-align: center;
}
</style>
</head>
<body>
<table width="980" border="0" align="center">
<tr>
<td width="20" height="25"><img src="../images/v7/HT.jpg" width="20" height="16" /></td>
<td width="54">汇银网 |</td>
<td width="57">汇金网 |</td>
<td width="17"><img src="../images/v7/phone.jpg" width="13" height="16" /></td>
<td width="74">手机汇通网 |</td>
<td width="67">软件中心 |</td>
<td width="21"><img src="../images/v7/set.jpg" width="16" height="16" /></td>
<td width="70">实用工具 |</td>
<td width="59">网站导航</td>
<td width="396"><span class="tui"></span> 欢迎来到汇银网,{$login_html}</td>
</tr>
</table>
<table width="980" height="100" border="0" align="center" cellspacing="0">
<tr>
<td width="250" rowspan="2"><img src="../images/v7/jiaoyi.jpg" width="172" height="47" /></td>
<td height="20" colspan="2"></td>
</tr>
<tr>
<td width="693" align="right"><input type="text" name="textfield" id="textfield" /></td>
<td width="31"><img src="../images/v7/sousou.jpg" width="30" height="25" /></td>
</tr>
</table>
<table width="980" border="0" align="center">
<tr>
<td width="564"> </td>
<td width="98"><img src="../images/v7/sy.jpg" width="98" height="29" /></td>
<td width="98"><img src="../images/v7/hd.jpg" width="98" height="29" /></td>
<td width="98"><img src="../images/v7/xx.jpg" width="98" height="29" /></td>
<td width="100"><img src="../images/v7/it.jpg" width="98" height="29" /></td>
</tr>
</table>
<table width="980" border="0" align="center" cellspacing="0">
<tr><form action="" name="myform" id="myform" method="">
<td width="220" valign="top"><label>标题</label> </td>
<td width="168" height="50" align="left">
<input name="biaoti" type="text" onblur="checkbiaoti();" /><br /><span id="check1"></span>
</label> </td>
<td width="586"> </td>
<tr>
<td valign="top">内容</td>
<td height="115" colspan="2" align="left">
<textarea name="contents" style="width:100%; height:100%" onblur="checkcontents();"></textarea>
</span></td>
</tr>
<tr>
<td valign="top"> </td>
<td height="50" align="left"><span id="check2"></span></td>
<td height="50" align="left"><input type="button" name="sub" value="提交" onclick="wc();"/></td>
</tr>
</form>
</table>
</body>
</html>其中js中的XHR.opne("POST","url",ture);url怎么写,fatie.php文件下的方法checkbiaoti!
网站的根目录是E:\wamp\www\hxsd。
fatie.php在hxsd/do/fatie.php.应该怎么写路径,求大神!!!
最佳答案