ajax webmethod,Jquery $.ajax() call to webmethod

博主正在尝试使用jQuery的$.ajax方法调用一个ASP.NET的Web方法,并希望添加额外的参数——所有特定div内复选框的名称、值和是否被选中状态。他们已经能够传递三个基本参数,但困惑于如何将复选框的数据以JSON格式添加到请求中。他们寻求关于如何在JSON中构建这种复杂数据结构的建议。
摘要由CSDN通过智能技术生成

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 definition of the webmethod should look something like this:

[WebMethod]

public static bool MyMethod(string a, string b, string c) {

...

}

The value for the data parameter in $.ajax() is:

myData => "'a':'val_a', 'b':'val_b','c':'val_c'"

Here is my ajax call:

$.ajax({

type: "POST",

url: "AspDotNetPage.aspx/MyMethod",

data: "{" + myData + "}",

contentType: "application/json; charset=utf-8",

dataType: "json",

success: function(msg) {

alert(msg);

}

});

Now the tricky part comes. I need to add an extra parameter to my webmethod. I must send to my webmethod all checkboxes inside a certain div, their names and if they are checked. I have Jquery code to select these values. Here is where i see in normal code-behind programming an additional parameter would be like

[WebMethod]

public static bool MyMethod(string a, string b, string c, Dictionary dict) {

...

}

that holds my checkbox text-value and if it's checked.

I haven't the foggiest idea how JSON actually works, all i know is that i have to make this work soon.

Probably some sort of multi dimensional javascripts arrays must be used. If you have any ideas on the best approach for this question i would be glad!

/Daniel Svensson, Sweden

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值