码迷,mamicode.com
首页 > Web开发 > 详细

用ajax实现评论刷新

时间:2016-09-02 18:50:14      阅读:240      评论:0      收藏:0      [点我收藏+]

标签:

前台代码:

<script src="jquery-1.8.3.js"></script>
<script type="text/javascript">
$(document).ready(function () {

$("#btn").click(function () {
var text = $("#txt").val();
var xmlhttp = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject(‘Microsoft.XMLHTTP‘);
xmlhttp.open("POST", "ajaxTest.ashx?txt=" + text, true);
xmlhttp.onreadystatechange = function () {
if (xmlhttp.readyState == 4) {
if (xmlhttp.status == 200) {
$("#span").html(xmlhttp.responseText);
$("#txt").val("");
}
else {
alert("AJAX服务出现了错误");
$("#txt").val("");
}
}
}
xmlhttp.send();
});
});
</script>

<body>
<video src="小事忠心.mp4" controls></video><br />
<label>评论:</label><br />
<span id="span"></span><br />
<textarea id="txt" style="width:670px;height:90px" name="txt"></textarea><br />
<input type="button" id="btn" value="提交" />
</body>

 

后台代码:

public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/html";
string pathFile = context.Server.MapPath("~/PL.txt");
string txt = File.ReadAllText(pathFile);
string retxt=context.Request["txt"];
string dt = DateTime.Now.ToString();
File.AppendAllText(pathFile, "\r\n" + dt + ":" + retxt + "<br/>");
txt = File.ReadAllText(pathFile);
context.Response.Write(txt);
}

技术分享

 

用ajax实现评论刷新

标签:

原文地址:http://www.cnblogs.com/jly-zyc/p/5834310.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!