Home » Jquery » salesforce get token using jQuery ajax method

salesforce get token using jQuery ajax method

Posted by: admin February 22, 2020 Leave a comment

Questions:

I have just intigrated the salseforce api using curl in php and its working fine but now i have to using the same thing with ajax so no curl is used here below is my code

var param = {
grant_type: "password",
client_id : "CLIENT_ID",
client_secret : "CLIENT_SECRET",
username:"USERNAME",
password:"PASSWORD"};
    $.ajax({
        url: 'https://test.salesforce.com/services/oauth2/token',
        type: 'POST',
        data: param,
        dataType: "json",
        crossDomain: true,
        contentType: "application/x-www-form-urlencoded",
        success: function (response) {
            console.log('Successfully retrieved ' + response);
            alert(JSON.stringify(response));
        },
        error: function (response) {
            alert(JSON.stringify(response));
        }

    });

when i alert the response than showing below response

enter image description here

and when inspect the response then showing below response

enter image description here

Please help me what’s wrong and how to solve this problem

Thanks

How to&Answer: