Home > jQuery > jQuery Ajax Call

jQuery Ajax Call

Code sample

$.ajax({
   url: GETURL,
   type: "GET",
   contentType: "application/json; charset=utf-8",
   dataType: "json",
   success: successCallback,
   error: errorCallback,
   dataFilter: function (data, type) {
      // ADO.NET Services return invalid JSON, 
      // so assign a pre-filtering function to sanitize the response
      return data.replace(/\\'/g, "'");
   }
});

function successCallback(result) {
   if (result != null) {
      data = result["d"][0];
      //data[PROPERTY_NAME] or data[0] etc;
   }
}

function errorCallback(xhr, ajaxOptions, thrownError) {
   alert("Error Occurred. Status - " + xhr.status + ",
   Error Text - " + thrownError + "Response Text - " +
   xhr.responseText);
}
Advertisements
Categories: jQuery
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: