2015-10-06 65 views
0

我正在傳遞strng數組值給處理程序。但我無法讀取HttpHandler ProcessRequest中的值。我怎樣才能得到這個價值?如何獲取HttpHandler ProcessRequest中的字符串數組值。

客戶機側代碼:

var advSearchTypes=["abc","def","ghi","jkl"]; $.ajax({ url: 'SearchHandler.ashx', type: 'post', data: ({"SearchKey": searchKey,"AdvSearchTypes": advSearchTypes}), 
    success: function (response) { }, error:function(){ } }); 

處理程序代碼:

public void ProcessRequest(HttpContext context) { 
    string aSearchKey = context.Request.Form["SearchKey"].ToString(); 

    string[] aSearchTypes = context.Request.QueryString["AdvSearchTypes"].Split(','); } 

context.Request.QueryString["AdvSearchTypes"]被示出爲空。

我怎樣才能得到我的字符串數組值。

+2

的Request.Form爲POST,查詢字符串爲GET –

+0

你最終會得到什麼像'AdvSearchTypes [] = abc&AdvSearchTypes [] = def ...'通過使用GET和類似的POST,通過'advSearchTypes.join(「,」)' –

回答

1

您可以在這裏

改變從type=postget

var advSearchTypes=["abc","def","ghi","jkl"]; $.ajax({ url: 'SearchHandler.ashx', type: 'get', data: ({"SearchKey": searchKey,"AdvSearchTypes": advSearchTypes}), 
    success: function (response) { }, error:function(){ } }); 

或者在處理程序代碼

public void ProcessRequest(HttpContext context) { 
    string aSearchKey = context.Request.Form["SearchKey"].ToString(); 

    string[] aSearchTypes = context.Request.Form["AdvSearchTypes"].Split(','); } 
相關問題