asp.net - Webmethod error with Jquery Ajax post function -
in asp.net 3.5 website, have jquery located in aspx page should execute function in code-behind. have used webmethod approach.
here error: system.argumentexception: unknown web method cloneitem. parameter name: methodname
here relevant code:
aspx page relevant part of jquery:
<%@ page language="vb" masterpagefile="~/pages/masterpage.master" title="planning" %> <%@ register tagprefix="pwc" namespace="pwc" %> <asp:content id="content1" contentplaceholderid="contentplaceholder1" runat="server"> <pwc:planning runat="server" skinfilename="core/planning.ascx" id="planning" secured="true"/> $("#dialog-form").dialog({ autoopen: false, height: 300, width: 350, modal: true, buttons: { "create clone": function () { var cloneitem = $('input[name=item]').is(":checked"); var intid = $(this).data('intid'); var bvalid = true; bvalid = bvalid && checkselections(); if (bvalid) { $.ajax( { type: 'post', url: 'planning.aspx/cloneitem', data: "{'(intid': '" + $(this).data('intid') + "', 'item': '" + cloneitem + "'}" , datatype: 'json', contenttype: 'application/json; charset=utf-8' // success: cloneonsuccess, // error: cloneonerror }); $(this).dialog("close");
function in planning.aspx vb code-behind:
imports system.web imports system.web.services <webmethod(enablesession:=true)> _ public shared function cloneitem(intid string, item boolean) string 'execute stored procedure here return "success!" end function
master page has following scriptmanager:
<ajaxtoolkit:toolkitscriptmanager id="scriptmanager1" runat="server" asyncpostbacktimeout="600" enablepartialrendering="true" combinescripts="false" scriptmode="release" enablepagemethods="true" > </ajaxtoolkit:toolkitscriptmanager>
any idea on doing wrong?
there 2 things might problem. first thing need code in web.config.
<system.web> <httpmodules> <add name="scriptmodule" type="system.web.handlers.scriptmodule,system.web.extensions, version=1.0.61025.0, culture=neutral, publickeytoken=31bf3856ad364e35"/> </httpmodules> </system.web>
see reference : call asp.net pagemethod/webmethod jquery - returns whole page
another thing need use json.stringify in parameter while posting data.
see reference - http://www.asp.net/ajaxlibrary/jquery_webforms_retrieve_data_from_pagemethod.ashx
Comments
Post a Comment