Bohdan Myslyvchuk
Bohdan Myslyvchuk

Reputation: 1817

How to get oAuth parameter using AJAX?

I'm new to ajax/jquery/javascript. So my iserver side uses oAuth. I need to obtain access code. So I'm sending request something like that :https:XXXX/OAuth.aspx?client_id=XXXXX&scope=full&response_type=code&redirect_uri=https%3A%2F%2Flocalhost%2F

If I'm logged I retrieve access code. So the issue is how to get this code with ajax, and how can I listen every time when it are changed. I wrote something like this, but it didn't work:

$.ajax({
url: "my-link",
data: {},
complete: function(xhr, statusText){
alert(xhr.status); 
}

});

Upvotes: 0

Views: 77

Answers (1)

Nomenator
Nomenator

Reputation: 1137

You can use the success parameter to grab your resulting response and do with it what you wish:

$.ajax({
    url: "my-link",
    data: {},
    success: function (response){
        alert(response);
    }
    complete: function(xhr, statusText){
        alert(xhr.status);
    }
};

You do have to fill in data properly and maybe you need other stuffs like processData and ContentType.

I rarely ever use “complete:”, mostly it’s “success:” and “error:” that handle everything I would need.

Upvotes: 1

Related Questions