Link to home
Start Free TrialLog in
Avatar of MJ
MJFlag for United States of America

asked on

JavaScript - How to Send Mixed Content Type in an Ajax Post?

This is similar to a previous post I made but I'm still confused and need help. I have two pieces of data to send to a service. I need to send, using javascript, an "action" which is JSON and I need to send a "submittingURL" which is just the encoded URL. Is there a way to send both pieces of data in the POST? If so how? This is all new to me. Below is the same function sending both as a GET and then the second one splits it so the JSON is POSTed. How can I send both via POST even though mixed content types (no jQuery)?
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)));
};`

Open in new window


Thanks!
ASKER CERTIFIED SOLUTION
Avatar of Julian Hansen
Julian Hansen
Flag of South Africa image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of MJ

ASKER

Let me look deeper into this and I'll let you know. Appreciate the input.
You are welcome.