2011-03-04 21 views
0
$.ajax({ 
       type: "POST", 
       url: "jquerychat.aspx/SendMessage", 
       data: "{msg:'Hello',userId:1}", 
       contentType: "application/json; charset=utf-8", 
       dataType: "json", 
       success: function (msg) { 
        // Replace the div's content with the page method's return. 
        // $("#txtMessages").val(msg.d);msg:'Hello', 
       }, 

       error: function(){ 
         alert('failure'); 
         } 

      }); 
     }); 

[WebMethod] 
public static string SendMessage(string msg,int userId) 
{ 
    NameValueCollection nvc = HttpContext.Current.Request.Form; 
    //string msg = "hello"; 
    //Int32 userId = 1; 
     LinqDataContext db = new LinqDataContext(); 


     message.Text = "json:" + msg; 

     db.Messages.InsertOnSubmit(message); 
     db.SubmitChanges(); 
     return "1"; 
} 

當我按下按鈕的ASPX Web方法是沒有得到所謂的......上面的代碼運行,如果我只使用一個參數在web方法..但可以訪問它時,我使用多個參數Web方法的語法

+0

「message.Text」中的'message'來自哪裏? – Harold 2011-03-04 09:23:52

回答

0

您可以檢查my reply到類似的問題。