$.ajax(..) and passing custom objects by ref

How to use $.ajax(..) JSON to invoke asmx webmethods that have 'by ref arguments' for custom classes/objects? Is it possible? My c# code - public class MyCustomClass{ public int MyProperty; MyCustomClass(){}} [WebMethod] [ScriptMethod(ResponseFormat = ResponseFormat.Json)] public Method1(ref MyCustomClass MyCustomObj) { MyCustomObj.MyProperty*=2; return MyCustomObj;} My js/jquery code - function myCustomClass(){this.myProperty;} var myCustomObj = new myCustomClass(); myCustomObj.myProperty = 100; $.ajax({ type: "POST", data: "{'myCustomObj': " + JSON.stringify(myCustomObj) + "}", url: "test.asmx/Method1", contentType: "application/json; charset=utf-8", dataType: "json", success: function(response) { var data = response.d; alert(data.MyProperty); }, failure: function(msg) { alert(msg); } }); This all works fine if the webmethod's argument is NOT by ref. With the above mentioned signature of the webmethod, i.e. with a by ref argument, I get a server error (in server response seen using firebub ) - No parameterless constructor defined...

以上就是$.ajax(..) and passing custom objects by ref的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » jQuery 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准

联系我们

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏