Click here to Skip to main content
15,894,405 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
hi all
i have one jscript file like:
JavaScript
saveSticky = function saveSticky() {
	    $.ajax({
	        type: "POST",
	        url: "Home.aspx/MethodSample",
	        data: "{}",
	        contentType: "application/json; charset=utf-8",
	        dataType: "json",
	        success: function succ(msg) {
	            alert('Called Ajax Method');
	        },
	        failure: function (response) {
	            alert(response);
	        }
	    });
	  
	    var that = $(this), sticky = (that.hasClass("sticky-status") || that.hasClass("sticky-content")) ? that.parents('div.sticky') : that,
                obj = {
                    id: sticky.attr("id"),
                    top: sticky.css("top"),
                    left: sticky.css("left"),
                    text: write = sticky.children(".sticky-content").html().search(document.getElementById("lblusername").value) <= 0 ? sticky.children(".sticky-content").html() + document.getElementById("lblusername").value : sticky.children(".sticky-content").html()
                }
	    localStorage.setItem("sticky-" + obj.id, JSON.stringify(obj));

	    sticky.find(".sticky-status").text("saved");
	    // alert('end to save stickey sticky-' + obj.id + ' ' + JSON.stringify(obj));
	}

am debug script code it works fine i did't get any errors while running code but
jquery method wont calling webmethod every time
my web method is like:
C#
[WebMethod]
   public static void MethodSample()
   {
       string str = "Hello World";
   }

so that i tried calling method like:
JavaScript
url: "organozation/Home.aspx/MethodSample"

but again it wont working i tried allot with different type but am not getting result so how can i call web method here...
can any one please help me..
thanks in advance
Posted
Updated 25-Dec-11 21:21pm
v3

1 solution

You need to add this code in web.config to enable calling WebMethods from javascript

HTML
<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>



Edited:

I missed the exact version for the ScriptHandler

For VS 2008. You need to use this

HTML
<httpModules>
       <add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
     </httpModules>
 
Share this answer
 
v2
Comments
tulasiram3975 26-Dec-11 4:29am    
Sir I added this To config File But It wont calling...
bbirajdar 26-Dec-11 8:06am    
I have added the exact version of script handler above. Try with this one

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900