I have a form with an action to the site that processes the post. When I hit submit with the url in the action, it works. Problem is, when the form is submitted or if there is an error, it takes me to another page so show "success" or "error" (I don't want it to take me to the other page, just return the response to my page so I can make a modal or something). I have tried many different ways, but when I use AJAX, I get the "Access-Control-Allow-Origin". Why would I get this if I'm already allowed to make the post without it?
Works when form header is:
form accept-charset="UTF-8" class="" id="contestForm" enctype="multipart/form-data" action='url' method='post'>
Example of requests I've made.
$.ajax({
method: 'POST',
url: url,
dataType: 'json' or 'jsonp',
headers: {'Access-Control-Allow-Origin: *},
)};
etc., etc. (Sorry that may not be complete as I have started over again before asking the question). Any idea how to not go to the submit page upon hitting the submit button?
P.s. I am using Flockler for the submissions and I have no control over how the data is posted to their server.
Please add the CORS header ‘Access-Control-Allow-Origin:<requster_domain>’ in the server to accept your request. Thru Ajax it opens up a security threat so the browsers block it which makes sense. else anyone can open a browser console and may bombard the server with ajax calls. But if your server trusts the calls coming from your domain, that security risk is mitigated.
I hope this helps.