当我们在用Ajax来返回一些数据时,除外一些我们要传入的参数外,还要传送一些数据到Ajax的页面,比如我们有一个资源的评论页面, 这个页面的数据是通过用Ajax来返回的,用户再对这个资源发表评论时这时我们就要回调Ajax了。把用户的评论标题和评论内容传送去,代码如下:
function Comment_Add(){
var m_title = document.getElementById("comment_title").value; //获得评论的标题
var m_content = document.getElementById("comment_content").value; //获得评论的内容
var level=Comment_GetLevel();
var url = "ContentAjax.aspx?resourceid=<% = resourceId %>&tableid=8";
var body = "comment_title=" + m_title + "&comment_content=" + m_content+"&level="+level;
var http_request = CreateXMLHttpRequest();
http_request.open('POST', url, true);
http_request.setRequestHeader("Content-Length", body.length); //在这里把评论标题和内容POST 过去 http_request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); //设置数据类型
http_request.onreadystatechange=function()
{
if(http_request.readyState==4)
{
if(http_request.status==200)
{
//Do something
}
}
}
http_request.send(body); //注意这里send的是评论标题和内容,不能为空等
}