A
A
Alexander Taran2014-11-24 23:42:40
JavaScript
Alexander Taran, 2014-11-24 23:42:40

How to catch Json received from a server with an existing api?

There is a server on which work it is impossible to influence in any way. The server has an API that describes the exchange of data with the client. The exchange comes down to sending and receiving data in JSON format.
Prompt how to catch the data received from the server.
For example: authorization code -

<form id="registration" action="http://192.168.1.10:8080/WebAPITaxi/Register" method="get">
    <input type="HIDDEN" name="app" value ="CxTaxiWebAPI">
     <label for="phone"></label> <input id="phone" name="phone" placeholder="89180000000"	 type="text">
     <br>
     <input type="submit">
  </form>

this is just html code with login and password fields
in response we get JSON
{ "success": true, "idClient": 5019196184, "params": {"ProtocolVersion":1,"RefreshOrdersSeconds":5,"LoginRegEx":"89[0-9]{9}$","MyPhoneRegEx":"89[0-9]{9}$","OurPhoneDisplay":"8-900-115-02-06","OurPhoneNumber":"+79181193434","DefaultServiceID":5006271953,"DefaultServiceName":"СТАНДАРТ","DefaultRegionID":5000370201,"DefaultRegionName":"Краснодарский край","DefaultDistrictID":null,"DefaultDistrictName":"","DefaultCityID":5000370202,"DefaultCityName":"Краснодар г","DefaultPlaceID":null,"DefaultPlaceName":""}, "sessionid": "37b2692167cbce2629b22f1b31e4" }

Now I get Json immediately on the page, but I need to catch this response using Javascript (as I understand it, you need to use ajax for this even before the get request was sent) and if "success": true then display a new form with other fields, if " success": false display an error.
Do I understand correctly that you need to send get requests using Javascript and jQuery with Ajax, catch responses and convert them to forms? Does anyone have the most similar examples to what I described above?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
asdz, 2014-11-24
@asdz

It's not difficult, read habrahabr.ru/post/42426/, but don't forget about cors

_
_ _, 2014-11-25
@AMar4enko

What level of difficulty are you?
This can be done with:
- VanillaJS
- jQuery
- Ember
- AngularJS
...there are dozens of different crafts.
Each of the methods has its pros and cons, its own entry threshold.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question