[whatwg/fetch] Fetch params and method confusion in ajax query (#1239)

Hi i want to use fetch with last fm api for get auth.getSession....

In ajax jquery would be something like:

```
var data = {
        'token': Utf8.encode(captured), //One caputered token
        'api_key': "c45b29231e8dc2ddc58480caba8cf4da",
        'method': 'auth.getSession'
    };
//Adding api_sig to data
data["api_sig"] = calculateApiSig( data);

//If i want data in json format

data["format"] = "json";

var last_url="http://ws.audioscrobbler.com/2.0/?";

    $.ajax({
        type: "GET",
        url: last_url,
        data:data,
        dataType: 'json',
        //"success" gets called when the returned code is a "200" (successfull request). "error" gets called whenever another code is returned (e.g. 404, 500).
        success: function(res){

            console.log("Resposta: Name " + res.session.name);// Should return session key.
            console.log("Resposta: Key " + res.session.key);

        },
        error : function(xhr, status, error){
            var errorMessage = xhr.status + ': ' + xhr.statusText
            console.log('Error - ' + errorMessage);
        }
    });
```
So id need translated to fetch...

```
var last_url="http://ws.audioscrobbler.com/2.0/?";

var data = {
        'token': Utf8.encode(captured), //One caputered token
        'api_key': "c45b29231e8dc2ddc58480caba8cf4da",
        'method': 'auth.getSession'
    };
//Adding api_sig to data
data["api_sig"] = calculateApiSig( data);

//If i want data in json format

data["format"] = "json";

fetch(last_url, data)
  .then(res => { //This happens with result success
            console.log("Resposta: Name " + res.session.name);// Should return session key.
            console.log("Resposta: Key " + res.session.key);

        },
  .catch(e => log("something went wrong: " + e)) /Id need error text, xhr status and xhrstatusText...
```
This query is get, and i got confused wiht method: get and method required for lastfm api_ method: auth.getSession 
( https://www.last.fm/api/show/auth.getSession)

Any help would be apreciated...



-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/fetch/issues/1239

Received on Saturday, 22 May 2021 18:34:59 UTC