c# - Ajax is not calling the webmethod -
i'm trying loadresources function work have put behind call of button - function called ajax fail (i "loading of engineers failed!" alert) , can't work out why
loadresources = function (instructionid) { var objresource = {}; objresource.instructionid = instructionid; objresource.ignorepostcode = true; objresource.pageindex = 1; objresource.pagesize = 10; objresource.totalrows = 0; var requestresource = $.ajax({ type: "post", url: "newjob.aspx/getresourcesdayshift", data: json.stringify(objresource), contenttype: "application/json; charset=utf-8", datatype: "json" }); requestresource.done(function (data) { alert(data); }); requestresource.fail(function () { //$.unblockui(); alert('loading of engineers failed!'); }); }
this method trying call:
[webmethod] public static string getresourcesdayshift(guid instructionid, bool ignorepostcode, int pageindex, int pagesize, ref int totalrows) { return "blah"; }
when call method next error message
message: "cannot convert object of type 'system.int32' type 'system.int32&'"
this problem ref parameters of method.
if want return data, can next change
[webmethod] public static object getresourcesdayshift(guid instructionid, bool ignorepostcode, int pageindex, int pagesize, int totalrows)//return ref keyword { return new { value = "blah", totalrows=totalrows+1 }; }
and on client side
requestresource.done(function (data) { console.log(data.d); //object {value: "blah", totalrows: 1} });
Comments
Post a Comment