Avatar of MJ
MJ
Flag 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!
JavaScriptAJAXJSON

Avatar of undefined
Last Comment
Julian Hansen

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Julian Hansen

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
MJ

ASKER
Let me look deeper into this and I'll let you know. Appreciate the input.
Julian Hansen

You are welcome.
Your help has saved me hundreds of hours of internet surfing.
fblack61