日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

ajax无刷新评论的思路,ajax学习——ajax版无刷新评论(数据库)

發布時間:2023/12/9 数据库 23 豆豆
生活随笔 收集整理的這篇文章主要介紹了 ajax无刷新评论的思路,ajax学习——ajax版无刷新评论(数据库) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

//Comment.htm

無刷新評論

type="text/javascript">

//加載評論

$(function() {

$.post("GetComment.ashx",

function(data, status) {

if (status != "success") {

$("#ulComment").append($("

加載數據失敗"));

return;

}

var lines =

data.split("$");

for (var i = 0; i < lines.length; i++) {

var line = lines[i];

var part = line.split("|");

var comment = $("

/>

用戶ip:"

+ part[0] + "

/>評論內容:" + part[1] +

"

/>時間:" + part[2] +

"

");

$("#ulComment").append(comment);

}

})

})

//評論

$(function() {

$("#btnPost").click(function()

{

var txtComment =

$("#txtComment").val();

$.post("SetComment.ashx", {

"comment": txtComment },

function(data, status) {

if (status != "success") {

alert("評論失敗,請重新評論");

return;

}

var lines =

data.split("|");

if (lines[0] == "ok") {

alert("謝謝評論");

var Comment = $("

/>

用戶ip:"

+ lines[1] + "

/>評論內容:" + txtComment +

"

/>時間:" + lines[2] +

"

");

$("#ulComment").append(Comment);

$("#txtComment").val("");//清除文本框內信息

}

else {

alert("數據錯誤");

}

})

})

})

style="width: 662px"

>

style="list-style-type:none">北京梁蓓委員談80后無力應對高房價的建議:我覺得80后男孩子如果買不起房子,80后女孩子可以嫁給

40歲的男人。80后的男人如果有條件了,到40歲再娶20歲的女孩子也是不錯的選擇。

id="txtComment"

cols="40"

rows="4">

/>

type="button"

id="btnPost"

value="提交評論"

/>

//SetComment.ashx

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.Services;

using ajax無刷新評論.DS_CommentTableAdapters;

namespace ajax無刷新評論

{

///

///

評論導入到數據庫,并返回數據

///

[WebService(Namespace = "http://tempuri.org/")]

[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]

public class

SetComment : IHttpHandler

{

public void ProcessRequest(HttpContext context)

{

context.Response.ContentType =

"text/plain";

string comment =

context.Request["comment"];

new

T_CommentTableAdapter().InsertQuery(context.Request.UserHostAddress,comment,DateTime.Now);

context.Response.Write("ok|"+context.Request.UserHostAddress+"|"+DateTime.Now);

}

public bool IsReusable

{

get

{

return false;

}

}

}

}

//GetComment.ashx

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.Services;

using ajax無刷新評論.DS_CommentTableAdapters;

using System.Text;

namespace ajax無刷新評論

{

///

///

數據庫中的數據送到頁面

///

[WebService(Namespace = "http://tempuri.org/")]

[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]

public class

GetComment : IHttpHandler

{

public void ProcessRequest(HttpContext context)

{

context.Response.ContentType =

"text/plain";

var comments = new T_CommentTableAdapter().GetData();

StringBuilder str = new StringBuilder();//字符串,很給力的字符串

foreach (var comment in comments)

{

str.Append(comment.IP).Append("|").Append(comment.Comment).Append("|").Append(comment.DateTime).Append("$");

//用"|"隔開每個字段,用"$"隔開每一行

}

context.Response.Write(str.ToString().Trim('$'));//把最后面的$去掉

}

public bool IsReusable

{

get

{

return false;

}

}

}

}

數據庫結構:

DataSet結構:

演示截圖:

總結

以上是生活随笔為你收集整理的ajax无刷新评论的思路,ajax学习——ajax版无刷新评论(数据库)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。