Created
January 10, 2011 19:19
-
-
Save dieseltravis/773291 to your computer and use it in GitHub Desktop.
Ajax in Asp.Net with jQuery
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SomePage.aspx.cs (ASPX codebehind) function | |
[System.Web.Services.WebMethod()] | |
[System.Web.Script.Services.ScriptMethod()] | |
public static string GetSomeObjects(string id) | |
{ | |
//TODO: get stuff here | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$.ajax({ | |
type: "POST", | |
url: "SomePage.aspx/GetSomeObjects", | |
// ^Page name ^public static function name | |
contentType: "application/json; charset=utf-8", | |
dataType: "json", | |
data: "{'id': '" + someId.replace(/'/g, "\\'") + "'}", | |
// ^Param ^value, escape apostrophe | |
success: function(json) { | |
// do something with JSON data, if necessary | |
$("#success").html("json.length=" + json.length); | |
}, | |
error: function (xhr, textStatus, errorThrown) { | |
// do something with error message, if necessary | |
$("#error").html(xhr.responseText); | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
' SomePage.aspx.vb (ASPX codebehind) function | |
<System.Web.Services.WebMethod()> _ | |
<System.Web.Script.Services.ScriptMethod()> _ | |
Public Shared Function GetSomeObjects(ByVal id As String) As String | |
'TODO: get stuff here | |
End Function |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment