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

How to access named pipes using JavaScript in Firefox add-on? -

multithreading - OPAL (Open Phone Abstraction Library) Transport not terminated when reattaching thread? -

node.js - req param returns an empty array -