MJ
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)?
Thanks!
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)));
};`
Thanks!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You are welcome.
ASKER