有人知道如何将以下curl命令转换为ajax/xmlhttpsrequest吗?
curl -d "username=username@company.com&client_secret=123456789&password=pwdgoeshere&grant_type=password&client_id=ReallyLongClientIDGoesHere" -H "Accept: application/json" https://login.salesforce.com/services/oauth2/token
我想实现类似以下两个示例的目标,但我的代码不起作用:
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);
});
最佳答案
我认为你需要这样的东西:
$.ajax({
url: "myUrl",
data: {
"username": username,
"VarB": VarB,
"VarC": VarC
},
cache: false,
type: "POST",
success: function(response) {
},
error: function(xhr) {
}
});
关于javascript - cURL 到 xmlhttprequest,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33759100/