Jquery $.ajax() call to webmethod

后端 未结 1 919
一个人的身影
一个人的身影 2021-01-20 22:29

I have never before used the $.ajax() and if you see any mistypes let me know ;)

Im using jQuery $.ajax() to call a webmethod with JSON.

The simple definitio

1条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-20 22:58

    if you make your bools nullable, you can just use the .serialize() method on all your values, and the checkboxes that aren't in the posted data will simply be ignored by the method:

    [WebMethod]
    public static bool MyMethod(string a, string b, string c, bool? chkbox1, bool? chkbox2....) {
           ...
    }
    

    you would need to add a bool? parameter for all your possible checkboxes on the page. that's the best way to provide a good method for testing etc. however if you really wanted to you could add another object to your data, for instance

    data: { 'a':'val_a', 'b':'val_b','c':'val_c', 'dict': { 'chk1', 'chk2', 'chk3' } }
    

    where chk1, chk2, chk3 is an array you've built of checked checkboxes, and your dict param would simply become a string array.

    0 讨论(0)
提交回复
热议问题