Skip to content

Instantly share code, notes, and snippets.

@faisal-w
Created February 20, 2014 07:31
Show Gist options
  • Save faisal-w/9108611 to your computer and use it in GitHub Desktop.
Save faisal-w/9108611 to your computer and use it in GitHub Desktop.
How to call a REST Service from Javascript
$(document).ready(function () {
$.ajax({
type: "GET",
url: "http://localhost/MyRESTService/ProductRESTService.svc/GetProductList/",
dataType: "xml",
success: function (xml) {
$(xml).find('Product').each(function () {
var id = $(this).find('ProductId').text();
var name = $(this).find('Name').text();
var price = $(this).find('Price').text();
var category = $(this).find('CategoryName').text();
$('<tr><td>' + id + '</td><td>' +
name + '</td><td>' + price + '</td><td>' +
category + '</td></tr>').appendTo('#products');
});
},
error: function (xhr) {
alert(xhr.responseText);
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment