Created
February 20, 2014 07:31
-
-
Save faisal-w/9108611 to your computer and use it in GitHub Desktop.
How to call a REST Service from Javascript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(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