我试图使用$ .post方法来调用Web服务,我已经使用$ .ajax方法工作了:
$.ajax({ type: "POST",url: "StandardBag.aspx/RemoveProductFromStandardBag",data: "{'standardBagProductId': '" + standardBagProductId.trim() + "' }",success: function(){ $((".reload")).click(); },dataType: "json",contentType: "application/json" });
但是当我将相同的方法移动到$ .post方法中时,它将无法正常工作:
$.post("StandardBag.aspx/RemoveProductFromStandardBag","{'standardBagProductId': '" + standardBagProductId.trim() + "' }",function () { $((".reload")).click(); },"json" );
我失踪了什么
解决方法
它不起作用,因为在$ .post方法中,您无法将请求的内容类型设置为application / json。所以不可能使用$ .post调用ASP.NET PageMethod,因为ASP.NET PageMethod需要一个JSON请求。你将不得不使用$ .ajax。
我只是修改数据,以确保它是正确的JSON编码:
$.ajax({ type: "POST",data: JSON.stringify({ standardBagProductId: standardBagProductId.trim() }),success: function() { $(".reload").click(); },contentType: "application/json" });
原文地址:https://www.jb51.cc/aspnet/252338.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。