大家好 我有一个jscript文件,例如:
hi all i have one jscript file like:
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)); }是调试脚本代码,它工作正常,我在运行代码时未收到任何错误,但 jquery方法不会每次都调用webmethod 我的网络方法就像:
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:
[WebMethod] public static void MethodSample() { string str = "Hello World"; }这样我就尝试调用像这样的方法:
so that i tried calling method like:
url: "organozation/Home.aspx/MethodSample"但再次它无法正常工作,我尝试使用其他类型的分配,但没有得到结果,所以我如何在这里调用Web方法... 任何人都可以帮我吗.. 在此先感谢
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
推荐答案.ajax({ 类型:" POST" , url:" Home.aspx/MethodSample" , 数据:" {}" , contentType:" application/json; charset = utf-8" , dataType:" json" , 成功:功能 succ(msg){ alert(' 被称为Ajax方法'); }, 失败:功能(响应){ 警报(响应); } }); var that = .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 ),粘性=(that .hasClass(" 粘性状态" )|| that.hasClass(" 粘性内容"))? that.parents(' div.sticky'): obj = { id:sticky.attr(" id" ), 顶部:sticky.css(" 顶部" ), 左:sticky.css(" 左" ), 文字:write = sticky.children(" .sticky-content" ).html().search( 文档 .getElementById(" lblusername" ) .value)< = 0 吗? sticky.children(" .sticky-content" ).html()+ 文档 .getElementById(" lblusername").value:sticky.children (" .sticky-content" ).html() } localStorage.setItem(" 粘性-" + obj.id, JSON .stringify(obj)); sticky.find(" .sticky-status" ).text(" 已保存"); // alert('结束保存Stickey Sticky-'+ obj.id +''+ JSON.stringify(obj) ); } (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)); }
是调试脚本代码,它工作正常,我在运行代码时未收到任何错误,但 jquery方法不会每次都调用webmethod 我的网络方法就像:
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:
[WebMethod] public static void MethodSample() { string str = "Hello World"; }这样我就尝试调用像这样的方法:
so that i tried calling method like:
url: "organozation/Home.aspx/MethodSample"但再次它无法正常工作,我尝试使用其他类型的分配,但没有得到结果,所以我如何在这里调用Web方法... 任何人都可以帮我吗.. 预先感谢
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
您需要在web.config中添加此代码,以启用从javascript调用WebMethods You need to add this code in web.config to enable calling WebMethods from javascript <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>
我错过了ScriptHandler的确切版本 对于VS2008.您需要使用此
Edited: I missed the exact version for the ScriptHandler For VS 2008. You need to use this
<httpModules> <add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/> </httpModules>
更多推荐
从asp.net中的js文件调用webmethod
发布评论