【问题标题】:cURL to xmlhttprequestcURL 到 xmlhttprequest
【发布时间】:2016-02-18 22:50:18
【问题描述】:

有人知道如何将下面的 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);
});

【问题讨论】:

  • 你没有发送帖子数据
  • 我不知道我的示例发布数据的格式如何。我对此很陌生

标签: javascript ajax curl oauth-2.0 xmlhttprequest


【解决方案1】:

我认为你需要这样的东西:

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

    },
    error: function(xhr) {

    }
});

【讨论】:

    猜你喜欢
    • 2010-11-01
    • 1970-01-01
    • 2011-07-19
    • 1970-01-01
    • 1970-01-01
    • 2022-01-17
    • 2015-08-31
    • 1970-01-01
    相关资源
    最近更新 更多