I try to do use Ajax (through jQuery) in asp.net website (using vb.net 2.0).
Here is my .aspx page (ajax.aspx):
<%@ Page Language="vb" AutoEventWireup="true" CodeFile="ajax.aspx.vb" Inherits="_Ajax" %>
<!DOCTYPE html>
<html>
<head>
<title>Calling page methods with jQuery</title>
<style type="text/css">
#Result {
cursor: pointer;
}
</style>
</head>
<body>
<div id="Result">Click here for the time.</div>
<script src="jquery-1.8.3.js"></script>
<script>
$('#Result').click(function () {
$.ajax({
type: "POST",
url: "ajax.aspx/HelloWorld",
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);
},
error: function (xhr, ajaxOptions, thrownError) {
alert("xhr.responseText= " + xhr.responseText);
alert("xhr.responseStatus= " + xhr.responseStatus);
alert("thrownError= " + thrownError);
}
});
});
</script>
</body>
</html>
And here is code-behind file (ajax.aspx.vb):
Imports System
Imports System.Web.Services
Public Class _Ajax
Inherits System.Web.UI.Page
Protected Sub Page_Load()
End Sub
<WebMethod()> _
Public Shared Function HelloWorld() As String
Return "Hello: "
End Function
End Class
When I click on my div, ajax call failed with:
System.ArgumentException: Unknown web method HelloWorld.
[EDIT]
After refresh and restart browser a lot of times, web method is found!
I try now to add a new web method, but I get error "unknown web method" again.
I think it's a cache problem.
Do you know how to force disable this kind of cache ?