前端
---------------------------------------------
以下的作法,是利用TagArticle函數將文章透過$.getJSON QueryArticle.ashx來取回資料。
function TagArticle(Sid,controlName,Ds ) { //標記文章
$.blockUI({ message: '
處理中,請耐心稍後喔…
' });
//990714 改善GET的Cache問題
$.getJSON("QueryArticle.ashx?Qid=" + Sid + "&d=" + Ds +"&q="+new Date().getTime(), function(Vdata) {
//處理 TAG 陣列
var tn="";
tn=Vdata.TagV;
//自動產生 Tag標記
var Slt='';
var cnt=0;
for( var i = 0; i < tagCnt; i++ ) { if( tn.indexOf("x" + (i+1) + "x" ) !=-1 ) { Slt=Slt + "" + (i+1) +'.' + tagN[i+1] + ' ' ;
} else {
Slt=Slt + "" + (i+1) +'.' + tagN[i+1] + ' ' ;
}
//每行排列三個控制項
cnt+=1 ;
if (cnt==4) {
Slt=Slt + "
"
cnt=0;
}
}
var XXX='';
XXX=Vdata.SugV
$("#Subj").html(XXX );
XXX=Vdata.MsgV
XXX =XXX.replace(/
/g,"\n")
XXX =XXX.replace(/(^\s*)|(\s*$)/g, "");
$("#Ac").val(XXX );
$("#Tagzone").html( Slt);
});
$.unblockUI(); //取消動畫!
---------------------------------------------
後端 QueryArticle.ashx
---------------------------------------------
'取得文章!
Dim ads As New AccessDataSource("~/App_Data/history.mdb", "")
Dim dv As Data.DataView
Dim s As String = ""
Dim LinkS As String = ""
ads.SelectCommand = "select tag,subject,Message,DiscussID from [oldarticle] where DiscussID=" & Qid
'990507以 StringBuilder 寫入 JSON 格式以供 前端JS再使用
Dim sb As New StringBuilder
dv = ads.Select(New DataSourceSelectArguments)
If dv.Count <> 0 Then
'MsgBox(dv.Item(0).Item("tag") & " " & dv.Item(0).Item("Message"))
'JOSN的基本格式如下()
'{ 'dataset' : [ {'categoryid' : 'A' , 'categoryname' : 'Cat'}
', {'categoryid' : 'B' , 'categoryname' : 'Mouse'}
', {'categoryid' : 'B' , 'categoryname' : 'Dog'}]}
'990507 因簡易版,只有1筆資料 故採此架構
'{
' "foo": "afsdfsafsdf.",
' "bar": "ABCDEFG",
' "baz": [52, 97]
'}
sb.Append("{ ")
sb.Append("""TagV"" : """ & dv.Item(0).Item("tag") & """ , ") '寫入第一個參數,tag
sb.Append("""SugV"" : """ & dv.Item(0).Item("subject") & """, ")
If SelDataSource = 0 Then '資料庫的名稱不同
Dim ads2 As New AccessDataSource("~/App_Data/@history.mdb", "")
Dim dv2 As Data.DataView
ads2.SelectCommand = "select Message,DiscussID from [oldarticle] where DiscussID=" & Qid
dv2 = ads2.Select(New DataSourceSelectArguments)
If dv2.Count <> 0 Then
sb.Append("""MsgV"" : """ & dv2.Item(0).Item("Message") & """} ") '寫入第2個參數,Message
End If
Else
sb.Append("""MsgV"" : """ & dv.Item(0).Item("Message") & """} ") '寫入第2個參數,Message
End If
'看不見的段落字元 很恐怖!! 會導致 JSON出現錯誤! 990622
sb.Replace(vbCrLf, "
")
sb.Replace(vbCr, "
")
sb.Replace(vbLf, "
")
'sb.Replace("
", "
")
' context.Response.Write(Replace(dv.Item(0).Item("tag") & "ckvkc" & dv.Item(0).Item("Message"), vbCrLf, "
"))
context.Response.Write(sb.ToString)
沒有留言:
張貼留言