0

Does anybody know how to translate the following curl command into ajax/ xmlhttpsrequest?

curl -d "[email protected]&client_secret=123456789&password=pwdgoeshere&grant_type=password&client_id=ReallyLongClientIDGoesHere" -H "Accept: application/json" https://login.salesforce.com/services/oauth2/token

I would like to achieve something like the following 2 examples , but my code doesn't work:

1)

var req = new  XMLHttpRequest();
  req.open( "POST", "https://login.salesforce.com/services/oauth2/token", true); 
  req.setRequestHeader('Accept', 'application/json');
  req.send();

2)

 $.ajax({
    url: myUrl,
    headers: myHeaders,
    type: 'POST',
    processData: false,
    contentType: false,

}).complete(function ( data ) {
    console.log(data.responseText);
});
2
  • Well you are not sending the post data Commented Nov 17, 2015 at 14:15
  • I don't know how the format the post data for my examples. I am quite new to this Commented Nov 17, 2015 at 14:17

1 Answer 1

1

I think that you need something like that:

$.ajax({
    url: "myUrl",
    data: { 
        "username": username, 
        "VarB": VarB, 
        "VarC": VarC
    },
    cache: false,
    type: "POST",
    success: function(response) {

    },
    error: function(xhr) {

    }
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.