0

I am trying to collect a token from a url by giving it the parameters ClientID and ClientSecret using a POST method.

This is my code:

jQuery(function(){

    $.ajax({
        "type":"POST",
        "url":"*******",
        "data":{clientID:"*****",clientSecret:"*****"}, 
        success:function(datos){ 
             console.log("Funciona")
         },
        "dataType": "json"
    })
})

However, when I run it I get error 405. Can anyone give me a hand?

Hakke
  • 1
  • 2
  • JSONP is **very very limited**. It does not support POST requests or custom headers. You are getting a Method Not Allowed error because you are making a GET request and the server expects a POST request. (This indicates that the server doesn't support JSONP so you shouldn't be trying to make a JSONP request in the first place). – Quentin Dec 05 '22 at 13:16
  • *Aside* `"crossDomain": true,` has no useful effect unless you are making a *same origin*, non-JSONP request that gets **redirected** to be cross-origin. – Quentin Dec 05 '22 at 13:17
  • Thank you very much for your comments. I have changed the "type" to GET, removed the "dataType" jsonp and removed the "crossDomain". But it still gives error 405, any idea? – Hakke Dec 05 '22 at 15:31
  • I said "You are getting a Method Not Allowed error because you are making a GET request". Changing the code to explicitly use GET instead of doing it implicitly via JSONP still means you are making a GET request (which the server says is not allowed). – Quentin Dec 05 '22 at 15:32
  • Thank you very much, sorry, I'm new to javascript. Its supposed I have to collect a token from a respective page. If the server says a GET request is not allowed. How could I collect the token then? – Hakke Dec 05 '22 at 15:37
  • Presumably by making a POST request. – Quentin Dec 05 '22 at 15:41
  • I thought I was making a POST request when I put it in type – Hakke Dec 05 '22 at 15:43
  • Read the first two sentences of my first comment again. – Quentin Dec 05 '22 at 15:44
  • First of all thank you very much for your patience :) – Hakke Dec 05 '22 at 15:58
  • I have edited the code, understanding your comments. What do you think? – Hakke Dec 05 '22 at 16:01
  • Now it should make a POST request. You've completely changed where the data is passed though. – Quentin Dec 05 '22 at 16:02
  • Is it still ok to pass the clientId and clientSecret that way or is it wrong? – Hakke Dec 05 '22 at 16:05
  • I have no idea how the API you are using expects the values to be passed. All I know is that it responds to GET requests with Method Not Allowed. – Quentin Dec 05 '22 at 16:06
  • You are helping me a lot, thanks for your time. What other ways are there to pass the data to the API besides this one? – Hakke Dec 05 '22 at 16:09
  • APIs in general: Too many to enumerate. The API you are using: How should I know? It should have documentation; use it. – Quentin Dec 05 '22 at 16:10

0 Answers0