Here I'm going to explain you the steps to POST complex data types to server using jQuery. The we technology whih I'm using here is ASP.NET MVC. You can make appropriate changes in url according to the server which you are using.
Use the following code:
$.ajax({
type: "POST",
contentType: "Application/json;charset=utf-8",
datatType: "json",
url: $("#_root").val() + "Client/SaveClientSession",
data: 1,
success: function (r) {
},
error: function (xhr, ajaxOptions,
thrownError) {
alert(xhr.status);
alert(thrownError);
alert(xhr.responseText);
}
});
type: "POST": Use either GET or POST as per your requirement
contentType: "Application/json;charset=utf-8": This is very important! You have to specify encoding, especially when you are passing complex data types
datatType: "json": Return type of the call
url: The destination url as per the server technology.
data: pass data to be passed. Use JSON.stringify if using complex types
success: callback function on successful call
success: callback function on error
No comments:
Post a Comment