简体   繁体   中英

Json based webservice in java and client in javascript

I am new in web service development. Currently I am developing an application (in html5 using javascript and jquery) in which I wanted to send data to web service in Json format.

My question are: 1) How to send(post) data to web service using javascript ? 2) How to retrieve json data at server side ? 3) How to get data from the web service in json format ? 4) How to retrieve json data at client side ?

Cast you json to string than send to server. In the server side cast it json again.

JSON is just a way to encapsulate data. You should have parses on both sides that parse the json into data you can work with. On your Java serve you can use eg https://code.google.com/p/json-simple/

  1. Easiest would be to use jquery ajax() function.

    $.ajax({ type: 'post', dataType: 'json', data: { "var1": value1, "var2": value2 }, url: 'www.example.com' }) .success( function() { console.log( 'success' ); });

  2. This depends on what backend do you use on server, I can reccomend node.js with express .

  3. The same as p1, the only difference that you will have to parse data you have received in success() function.

  4. I am not sure if I understand correctly what you mean.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM