0

I'm new to Web development, usually I'm used to software development but studying web development confuses me a lot. please forgive my newbie question

What I'm trying to do is test every domain that is inside my array(dMains) so that every domain can be checked by the script since the goal is to make it work for every domain. Hope u guys can help me thanks a lot.

<!DOCTYPE html>
<html>
    <body onload="loopdMains()">
        <script>history.pushState('', '', '/')</script>
        <script>
            var dMains=["my.firstdomain.com","my.seconddomain.com"];

            function loopdMains()

            {
                for(var i=0;i<dMains.length;i++)
                {

                <form action=(i) method="POST">
                <input type="hidden" name="type" value="excl" />
                <input type="hidden" name="action" value="update" />
                <input type="hidden" name="period" value="1" />

                }
            }

        </script>
    </body>
</html> 
BRond
  • 57
  • 8
  • You cannot directly write HTML in JavaScript code. See [this post](https://stackoverflow.com/questions/2895318/appendchild-createelement). Create a string and then append it to the DOM. – 31piy May 07 '18 at 03:13
  • What are you trying to achieve ? – Prajval M May 07 '18 at 03:15
  • You can change the form action using JavaScript like `document.querySelector('form').action = dMains[i]`. If you're trying to test an API call on multiple domains, I'd suggest using a better tool like Postman with multiple environments. – Sean May 07 '18 at 03:15
  • @31piy ok thank u I'll study it. – BRond May 07 '18 at 03:19
  • @PrajvalM to loop every single domain in "form action". E.G. First loop
    together with 3 lines of code below. Second loop
    – BRond May 07 '18 at 03:20
  • @Sean thank u, will try. – BRond May 07 '18 at 03:20
  • So basically you want to send post request to all these domains – Prajval M May 07 '18 at 03:23

1 Answers1

1

If you want to just send post requests and check for the response use xhhtp, jquery or axios to do the post request. Attach a eventListener to your window object and trigger it when you have a response. You have option to set the url in these Eg.

//JQuery
$.ajax({ 
  type: "POST",
  url: url,
  data: data,
  success: success,
  dataType: dataType
}

//axios
axios.post(url, callbackFunction);

in your loop set url parameter and in your call back once you get response dispatch the event. Listen to 6 of such and after that your are done.

Prajval M
  • 2,298
  • 11
  • 32