JSON學習
學習資料
- 入門資料
1, 深入淺出JSON ( http://www.cnblogs.com/Truly/archive/2006/12/31/608896.html )
2, JavaScript中的JSON ( http://www.dreamdu.com/blog/2008/10/19/json_in_javascript/ )
使用
1,GetWF.ashx文件
<%@ WebHandler Language="VB" class="GetWF" %>
Imports System
Imports System.Web
Public Class GetWF : Implements IHttpHandler
Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
context.Response.ContentType = "text/plain"
Dim _wf As String = "[[{WN:'a'},{WV:'aV'}],[{WN:'b'},{WV:'bV'}]]"
Dim _reqNo As String = context.Request.QueryString("CheckRequestNo")
Dim _wfpersent As String = Global.WorkFlow.GetPresentWFIdByReqId(_reqNo)
'------------------------------------------------------------------
Dim db As New DBUtility.DatabaseHelper
Dim sb As New Text.StringBuilder
Dim ds As New Data.DataSet
sb.Append(" select distinct rw.WF_id,rw.WF_CODE from workflow rw ")
sb.Append(" where rw.WF_ID<'130' ")
sb.Append(" and rw.wf_id>='" & _wfpersent & "' ")
ds = db.ExecuteDataSet(sb.ToString())
_wf = "["
_wf += "[{WN:''},{WV:''}],"
For Each dr As Data.DataRow In ds.Tables(0).Rows
_wf += "[{WN:'" & dr("WF_id").ToString() & "'},{WV:'" & dr("WF_CODE").ToString() & "'}]" + ","
Next
_wf = Global.StringUtility.DelLastComma(_wf)
_wf += "]"
'------------------------------------------------------------------
context.Response.Write(_wf)
End Sub
Public ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
Get
Return False
End Get
End Property
End Class
2,ASPX
<asp:DropDownList ID="ddlWorkFlow" runat="server" AutoPostBack="True" CausesValidation="True">
</asp:DropDownList>
3,JS
function setDropListWF()
{
$.ajax({
type: "GET",
url: "CheckRequestNo.ashx",
data: "CheckRequestNo="+$("#txtSourceReqeustNo").val(),
success: function(result){
if(result==0)
{
alert("申請單號不存在");
return false;
}
else
{
$.ajax({
type: "GET",
url: "GetWF.ashx",
data: "CheckRequestNo="+$("#txtSourceReqeustNo").val(),
success: function(result){
//alert(result);
eval("wf="+result);
//alert(wf[0][0].WN+wf[0][1].WV);
var ddlWF=document.getElementById("ddlWorkFlow")
//ddlWF.options.add();
var l=ddlWF.options.length
for(var i=0;i<l;i++)
{
ddlWF.remove(0);
}
for(var i=0;i<wf.length;i++)
{
ddlWF.add(new Option(wf[i][1].WV,wf[i][0].WN));
//alert(wf[i][0].WN);
}
form1.submit();
}
});
}
}
});
}