Sunday, July 3, 2011

jQuery ajax function template

Example

$.ajax({
url: "/Home/Index",
data: { email: email, username: username, etc: etc },
success: function (data) {
debugger; // remove debugger before check-in.
$("#somelabel").text(data.SomeText);
},
type: "POST",
dataType: 'json'
});

Another example

$.ajax(
{
url: "/Account/LogOn",
type: "POST",
dataType: 'json',
data: {
username: $("txtUserName").val(),
password: $("txtPassword").val(),
rememberMe: $("#chkRememberMe").is(':checked')
},
success: function (mydata) {
if(mydata.Success) {
alert(mydata.WelcomeMessage);
}
else{
alert(mydata.Error);
}
}
});

No comments: