JQuery and JSON Web Service

Use JQuery to consume JSON Web Services is a lightweight method, for increment performance in your website.

If you want call a JSON Web Service from your javascript code, you should : use HTTP POST and content-type "application/json; charset=utf-8″. Asp.Net Ajax make this for you transparently.

$(document).loadMyContent(function() {
$.ajax({
type: "POST",
url: "myService.asmx/GetMyContent",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(msg) {
$('#myDiv').html(msg.d);
}
});
});

Insert javascript code after content for best performance.

0 comments: