Consume java RESTful Webservice with jQuery -


enter image description hereconsuming 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

Popular posts from this blog

java - Intellij Synchronizing output directories .. -

git - Initial Commit: "fatal: could not create leading directories of ..." -