保存对 jQuery 可排序表的更改
我有一个表,允许用户按照他们想要的顺序拖放行,然后保存它们。我对拖放部分的工作没有任何问题。这是我遇到问题的储蓄。我正在向 Web 服务发送 Ajax 调用,然后该服务将进行保存。不过,我似乎无法真正捕获网络服务中的请求。
我的 JavaScript 函数如下所示:
$(document).ready(
function () {
$(".sortable").sortable({
update: function () {
serial = $('.sortable').sortable('serialize');
$.ajax({
url: "MyWebService.asmx/SortTable",
type: "post",
data: serial,
error: function () {
alert("theres an error with AJAX");
}
});
}
});
});
从 Firebug 向我展示的内容来看,JSON 字符串看起来不错。 Web 服务功能就像这样:
[WebMethod]
public string SortTable(String[] rows)
{
//SaveChanges();
return "Called!";
}
当我在那里放置断点时,它永远不会被命中。当函数中没有参数时,它就会被命中。我尝试用“object”替换“String[]”,但它仍然没有被击中,我觉得这很奇怪。这是怎么回事?
I have a table where the users are allowed to drag and drop rows in the order they want, and then save them. I have no problem with getting the drag and drop part to work. It's the saving I'm having issues with. I'm sending an Ajax call to a web service which will then make the save. I can't seem to actually catch the request in the web service though.
My JavaScript function looks like so:
$(document).ready(
function () {
$(".sortable").sortable({
update: function () {
serial = $('.sortable').sortable('serialize');
$.ajax({
url: "MyWebService.asmx/SortTable",
type: "post",
data: serial,
error: function () {
alert("theres an error with AJAX");
}
});
}
});
});
The JSON string looks fine from what Firebug is showing me. The web service function is like so:
[WebMethod]
public string SortTable(String[] rows)
{
//SaveChanges();
return "Called!";
}
When I put a breakpoint in there, it never gets hit. When there are no arguments in the function though, it will get hit. I've tried replacing "String[]" with "object" and it still doesn't get hit, which I find odd. What is going on here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可能需要使用
[ScriptService]
属性来装饰您的 Web 服务,以便允许客户端脚本调用它。此外,如果您要发送 JSON 请求,则需要指定内容类型。另一个注释是将请求作为实际的 JSON 对象发送,这可以使用 JSON.stringify 方法来实现(可能是 $('.sortable').sortable('serialize')< /code> 调用已经做到了这一点,我不熟悉,你只需要确保 POSTed 值如下所示:[ 'row1', 'row2', ... ]
):You might need to decorate your web service with the
[ScriptService]
attribute in order to allow client scripts to invoke it. Also if you are sending a JSON request you need to specify the content type. Another remark is about sending the request as an actual JSON object which could be achieved using theJSON.stringify
method (maybe the$('.sortable').sortable('serialize')
call already does this, I am not familiar, you just need to ensure that the POSTed value looks like this:[ 'row1', 'row2', ... ]
):