我在cliend一侧创建了一本字典,并希望将它发送到服务器端。在我的脚本中,字典是正确创建的,但我不确定放弃我的ajax代码。将数据从ajax发送到c#服务器
$("#btnSubmit").click(function() {
var sendList = new Array();
var elems = $(".elemValue");
$.each(elems, function (key, value) {
if (value.attributes.elemName.nodeValue != "PhotoImg") {
sendList[value.attributes.elemName.nodeValue] = value.attributes.value.nodeValue;
}
});
var data = JSON.stringify({dict : sendList});
$.ajax({
type: "GET",
url: "dataloader.aspx/GetData",
data: data,
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (result){
alert(result.d);
}
});
});
在服务器端,我写
[System.Web.Services.WebMethod]
public static string GetData(Dictionary<string,string> dict)
{
Dictionary<string, string> serverDict = new Dictionary<string, string>();
serverDict = dict;
string result = "";
foreach (var value in dict)
{
result += "The key is:" + value.Key + "The value is:" + value.Value;
}
return result;
}
哪里是我的错误,我怎样才能解决这些问题?帮助,请=)
您是否收到任何错误? – Andrei
不,任何错误。只是脚本根本不工作。即使是VS调试器也不会被调用。 –
所以脚本没有发出AJAX请求? –