JavaScript - 如何在帖子中发送混合内容类型?

时间:2018-05-16 23:15:20

标签: javascript json post get http-headers

我有两个数据要发送到服务。我需要使用javascript发送"动作"这是JSON,我需要发送一个" submittingURL"这只是编码的URL。有没有办法在POST中发送两个数据?如果是这样的话?这对我来说都是新的。下面是同一个函数发送两个作为GET,然后第二个分割它,以便JSON被POST。

function sendUnapprovedAction(action) {
    var req = new XMLHttpRequest();
    var url = '//001l60fbadm:10001/marketingcampaigns/api/v1/campaigns?action=' +
    encodeURIComponent(JSON.stringify(action)) + '&submittingURL=' + 
    encodeURIComponent(_satellite.getVar("Full URL"));
    req.open('POST', url, true);
    req.setRequestHeader('Content-Type', 'application/json');
    req.send();
};

function sendUnapprovedAction(action) {
    var req = new XMLHttpRequest();
    var url = '//001l60fbadm:10001/marketingcampaigns/api/v1/campaigns?submittingURL=' +
    encodeURIComponent(_satellite.getVar("Full URL"));
    req.open('POST', url, true);
    req.setRequestHeader('Content-Type', 'application/json');
    req.send('action=' + encodeURIComponent(JSON.stringify(action)));
};`

0 个答案:

没有答案