Thursday, 15 March 2012

javascript - Using POST and GET to Exchange Data Through Endpoints -


Although I'm trying to build a web app, however, I am finding out the lack of their tutorials . The way this works, that data is sent back using POST and GET functionality and using JSON. Feel easy enough, want to get information about an artist? Just call https://api.spotify.com/v1/artists/0OdUWJ0sBjDrqHygGUXeCF and receives a good JSON document with information about the artist you requested.

The problem is I do not know how to call GET, JQuery meets both "methods" with parameters and post but I'm not sure it is necessary for syntax, especially when it's a It comes to exchange authorization codes for access tokens. If you travel and scroll to step 4 of the authorization code flow, then you can see that I have to make a post call to https://accounts.spotify.com/api/token . There should be 3 request body parameters and 1 header parameter in the call and a JSON file response body with proper data on the succession.

My question is how do I post and GET calls that the body parameters and header parameters and how do I remove JSON data from the feedback group after a successful call?

As you can see about them and about them, their getUserData requests only call a simple Ajax , In which their URL and a header object (which includes a prefix string with access-token) is in the form of parameters:

  function getUserData {accesstooken} {return $. Ajax ({url: 'https://api.spotify.com/v1/me', header: {'Authority': 'Barrier' + AccessToken}}); }  

Generally, when you get a $ Ajax code needs to pass the parameter, just do as shown above or create an object before and like it:

your obj = {url} : "Your URL here", Ultimate 2: "Ultimate Vel 2", Ultimate 3: "Ultimate Vel 3", ...} $ .ajax (Your obiez). (Function (data) {/} Do something with the data returned here, such as console.log ("data:", data);});

This method may be useful if your parameters are dependent on other values ​​which are not so easily available.


No comments:

Post a Comment