2012-10-04 47 views
0

如何將參數從javascript/jquery傳遞給通用處理程序(Asp.net)?我如何將參數傳遞給通用處理程序

我爲jquery pluginajaxfileupload)的通用處理器,我需要從頁面傳遞一些參數(jQuery的/ JavaScript的) (例動態保存路徑,autogenerated filename,等...)

回答

2

及其工作如下:

$.ajaxFileUpload(
{  
    url: 'MyHandler.ashx?filename=test.png&path=../test/Images' 
     secureuri: false, 
     fileElementId: 'fileToUpload', 
     dataType: 'json', 
     data: { name: 'logan', id: 'id' }, 
     success: function(data, status) { 
      if (typeof (data.error) != 'undefined') { 
       if (data.error != '') { 
        alert(data.error); 
       } else { 
        alert(data.msg); 
       } 
      } 
     }, 
     error: function(data, status, e) { 
     alert(e); 
    } 
}) 

在通用處理器

public void ProcessRequest(HttpContext context) 
{ 
    string stringParam = (string)context.Request["filename"]; 
} 

另一種解決方案

var strFileName="test.png"; 
$.ajaxFileUpload( 
{  
    url: 'MyHandler.ashx?filename=test.png&path=../test/Images' 
     secureuri: false, 
     fileElementId: 'fileToUpload', 
     dataType: 'json', 
     data: { name: 'logan', id: 'id',filename: strFileName }, 
     success: function(data, status) { 
      if (typeof (data.error) != 'undefined') { 
       if (data.error != '') { 
        alert(data.error); 

       } else { 
       alert(data.msg); 

       } 
      } 
     }, 
     error: function(data, status, e) { 
     alert(e); 
    } 
}) 
相關問題