Consume java RESTful Webservice with jQuery -
consuming restful webservice jquery want achieve. after following tutorial successfully. 1 of file type json file. want read values json file displayed on html file using jquery. code written far test this,but not giving right output, can do? in advance. jquery file
$(document).ready(function() { $.ajax({ url: "http://localhost:8080/wmwebserviceapplication/webresources/com.mycompany.wmwebserviceapplication" }).then(function(data) { $('.discountcode').append(data.discountcode); $('.rate').append(data.rate); }); });
these parameters of webservice created using java
url: http://localhost:8080/wmwebserviceapplication/webresources/com.mycompany.wmwebserviceapplication.discountcode
json parameters , values
[{"discountcode":"h","rate":16.00},{"discountcode":"m","rate":11.00},{"discountcode":"l","rate":7.00},{"discountcode":"n","rate":0.00}]
request method
![get(application/json)][3]
it's because you're receiving array of objects in json, example if you'd access first element, should write:
$(document).ready(function() { $.ajax({ url: "http://localhost:8080/wmwebserviceapplication/webresources/com.mycompany.wmwebserviceapplication" }).then(function(data) { $('.discountcode').append(data[0].discountcode); $('.rate').append(data[0].rate); }); });
Comments
Post a Comment