cURL 到 xmlhttprequest
cURL to xmlhttprequest
有人知道如何将以下 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
我想实现类似于以下 2 个示例的东西,但我的代码不起作用:
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) {
}
});
有人知道如何将以下 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
我想实现类似于以下 2 个示例的东西,但我的代码不起作用:
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) {
}
});