Mar*_*tin 6 c# ajax jquery webmethod
我知道那里有类似的帖子,但我发现其中任何一个都没有帮助.
我的网络方法在我不使用网址重写时工作,但是一旦打开它就停止工作.
jQuery的
$.ajax({
type: "POST",
url: "index.aspx/SaveSetting",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(msg) {
console.log(msg);
}
});
Run Code Online (Sandbox Code Playgroud)
C#
[WebMethod()]
[ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)]
public static string SaveSetting()
{
return "OK";
}
Run Code Online (Sandbox Code Playgroud)
当调用它时,我得到了我的页面的完整HTML,没有"OK"消息.我运行调试器,看到当我调用web方法时,它会在我的页面中触发Page_Load而不是web方法.
所以我得到了corerct路径,但没有调用web方法.
我使用C#,jQuery,ASP.NET 3.5.
有帮助吗?
您需要使用指向您的 Web 方法的完整链接。
如果你查看 firebug 你会看到,例如:
http://localhost/test1/index.aspx/SaveSetting作为您尝试请求的 url,假设 /test1 重写为 /index.aspx
假设该页面位于您网站的根目录,则以下内容将起作用:
网址:/index.aspx/保存设置
(顺便说一句,这对于 url 路由根本不起作用!)
也许可以将您的 Web 方法移至 asmx 文件中?
| 归档时间: |
|
| 查看次数: |
3417 次 |
| 最近记录: |