亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

Json實(shí)現(xiàn)異步請(qǐng)求提交評(píng)論無(wú)需跳轉(zhuǎn)其他頁(yè)面

 更新時(shí)間:2014年10月11日 17:47:43   投稿:whsnow  
Json實(shí)現(xiàn)異步請(qǐng)求,效果即為,在輸入框中輸入相關(guān)文字,點(diǎn)擊提交,下方會(huì)自動(dòng)將書寫的文字進(jìn)行展示,無(wú)需跳轉(zhuǎn)其他頁(yè)面

主要將代碼粘貼,通過(guò)閱讀代碼理解其中的相關(guān)邏輯。

html代碼:

<form id="form1" runat="server"> 
<p> 
評(píng)論:</p> 
<p> 
姓名:<input type="text" name="username" id="username1" /></p> 
<p> 
內(nèi)容:<textarea name="content" id="content" rows="2" cols="20"></textarea></p> 
<p> 
<input type="button" id="send" value="提交" /></p> 
</form> 
<div class="comment"> 
已有評(píng)論:</div> 
<div id="resText"> 
</div>

js代碼:

$("#send").click(function () { 
$.get("doSave.ashx", {<span style="white-space:pre"> </span> <span style="font-family: Arial, Helvetica, sans-serif;"> </span>//調(diào)用json插件 
u_name: $("#username1").val(), //json數(shù)據(jù)/值對(duì)化 
u_cont: $("#content").val() 
}, function (data) 
var uName = data.username; //注:此處的username與doSave.ashx中的dic.add("username",uname)中的username相對(duì)應(yīng)的 
var uCont = data.content; 
var txtHtml = "<div class='comment'><h6>" 
+ uName + ":</h6><p class='para'>" 
+ uCont + "</p></div>" 
$("#resText").html(txtHtml); //將返回的數(shù)據(jù)添加到頁(yè)面上 
}, "json"); 
})

插件代碼:

<%@ WebHandler Language="C#" Class="doSave" %> 

using System; 
using System.Web; 

public class doSave : IHttpHandler 
{ 

public void ProcessRequest(HttpContext context) 
{ 

var dic = new System.Collections.Generic.Dictionary<string, object>(); //存儲(chǔ)的集合 
string jsonStr = "{}"; //新建字符串jsonStr 

context.Response.ContentType = "text/json"; //定義返回的內(nèi)容類型為json 

string uname = context.Request.QueryString[0]; //獲取請(qǐng)求參數(shù)中第一個(gè)參數(shù),也可以直接使用uname 

string commet = context.Request.QueryString[1]; //定義字符串uname、commet為context請(qǐng)求查詢的字符串context.Request.Params["username"];QyertStrubg:查詢字符串 

dic.Add("username", uname); //將字符串添加到對(duì)象中 

dic.Add("content", commet); 

jsonStr = Newtonsoft.Json.JsonConvert.SerializeObject(dic); //序列化集合為json字符串 

context.Response.Write(jsonStr); 
} 

public bool IsReusable 
{ 
get 
{ 
return false; 
} 
} 

}

此處效果即為,在輸入框中輸入相關(guān)文字,點(diǎn)擊提交,下方會(huì)自動(dòng)將書寫的文字進(jìn)行展示,無(wú)需跳轉(zhuǎn)其他頁(yè)面。

相關(guān)文章

最新評(píng)論