Well i started by creating a new asp.net webapplication in VS2010 It created a solution that included jquery 1.4.1
After that i created an file named ajax.aspx and added the following in the code behind file:
<WebMethod()> _
<ScriptMethod(ResponseFormat:=ResponseFormat.Json)> _
Public Shared Function GetDate() As String
Return Date.Now.ToString()
End Function
Then i added the following to "HeaderContent" in the "Default.aspx" file
<script language="javascript" type="text/javascript">
$(document).ready(function () {
$.ajax({
type: "POST",
url: "Ajax.aspx/GetDate",
data: "{}",
contextType: "application/json; charset=utf-8",
dataType: "json",
success: function (msg) {
var result = msg.d;
alert(result);
},
error: function (msg) {
alert("Failed!");
}
});
});
</script>
and i added the Jquery js reference in the master page..
but when i run the project i get "Failed" and the response text is the content of my ajax.aspx... why does this give me the content and not the result of the function?
Note: the GetDate function is never run (i placed a break point there)