我试图使用jQuery直接调用ASP.NET AJAX页面方法.我正在使用encosia.com作为参考.我的内联JavaScript是
<script type="text/javascript">
$(document).ready(function() {
// Add the page method call as an onclick handler for the div.
$("#Result").click(function() {
$.ajax({
type: "POST",
url: "Default.aspx/GetDate",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(msg) {
// Replace the div's content with the page method's return.
$("#Result").text(msg.d);
}
});
});
});
</script>
<div id="Result">Click here for the time.</div>
Run Code Online (Sandbox Code Playgroud)
用我的webmethod
<WebMethod()> _
Public Shared Function GetDate() As String
Return DateTime.Now.ToString()
End Function
Run Code Online (Sandbox Code Playgroud)
我会使用FF并检查发送的POST,但是因为我目前只有IE 7,所以这有点难.其他相关信息,ASP.net 2.0.有谁知道我做错了什么?
web.config - 预先存在仍然无法正常工作
<httpModules>
<remove name="FormsAuthentication" />
<remove name="PassportAuthentication" />
<add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
</httpModules>
Run Code Online (Sandbox Code Playgroud)
由于您使用的是ASP.NET 2.0,因此需要安装ASP.NET AJAX Extensions,如Joe Enos所述.我在这里有关于必要配置工作的更多信息:http://encosia.com/asmx-scriptservice-mistakes-installation-and-configuration/
此外,.d响应周围的包装是一个添加,直到ASP.NET 3.5.所以,即使你已经完成了其他一切工作,你msg.d也将使用undefinedASP.NET 2.0.省略.d并且只是做到:
success: function(msg) {
// Replace the div's content with the page method's return.
$("#Result").text(msg);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4074 次 |
| 最近记录: |