That's the link where I tried this sample and decided if I could use more than one GET.
I'm using the jquery ajax exactly as shown in this sample but with one additional one for the name:
<script type="text/javascript">
$(document).ready(function () {
// for GetAllProducts
$.getJSON("api/products/", function (data) {
// on success, 'data' contains a list of products
$.each(data, function (key, val) {
// format the text to display
var str = val.Name + ': $ ' + val.Price;
// add a list item for the product
$('<li>', { html: str }).appendTo($('#products'));
});
});
// for GetProductById
$('#find').click(function () {
var id = $('#prodid').val();
$.getJSON('api/products/' + id, function (data) {
var str = data.Name + ': $' + data.Price;
$('#product').html(str);
})
.fail(
function (jqXHR, textStatus, error) {
$('#product').html('Error: ' + error);
});
});
// for GetProductByName()
$('#findname').click(function () {
var name = $('#nameid').val();
$.getJSON('api/products/' + name, function (data) {
var str = data.Name + ': $' + data.Price;
$('#product').html(str);
})
.fail(
function (jqXHR, textStatus, error) {
$('#product').html('Error: ' + error);
});
});
});
</script>
zebula8
Member
9 Points
7 Posts
Re: How many number of GETs, POSTs allowed ?
Feb 19, 2012 07:42 PM|LINK
[http://www.asp.net/web-api/overview/getting-started-with-aspnet-web-api/tutorial-your-first-web-api]
That's the link where I tried this sample and decided if I could use more than one GET.
I'm using the jquery ajax exactly as shown in this sample but with one additional one for the name:
<script type="text/javascript"> $(document).ready(function () { // for GetAllProducts $.getJSON("api/products/", function (data) { // on success, 'data' contains a list of products $.each(data, function (key, val) { // format the text to display var str = val.Name + ': $ ' + val.Price; // add a list item for the product $('<li>', { html: str }).appendTo($('#products')); }); }); // for GetProductById $('#find').click(function () { var id = $('#prodid').val(); $.getJSON('api/products/' + id, function (data) { var str = data.Name + ': $' + data.Price; $('#product').html(str); }) .fail( function (jqXHR, textStatus, error) { $('#product').html('Error: ' + error); }); }); // for GetProductByName() $('#findname').click(function () { var name = $('#nameid').val(); $.getJSON('api/products/' + name, function (data) { var str = data.Name + ': $' + data.Price; $('#product').html(str); }) .fail( function (jqXHR, textStatus, error) { $('#product').html('Error: ' + error); }); }); }); </script>