Skip to content Skip to sidebar Skip to footer

Window.location.href Using Get When I Need Post

I have the following script, a few lines up from the bottom I have a window.location.href which posts the reults from my form though the address bar. This is very messy and I would

Solution 1:

The only way to make a POST request with the response rendered directly into the browser window is to use a form (which you generate with DOM) and submit it (which you can likewise do through DOM).

The alternative is to use XMLHttpRequest (or some other Ajax technique) and render the response with DOM.

Solution 2:

There is no need to pass form data as GET data. You can specify the method as POST.

<formaction="script.asp"method="post">
   ...
   <inputtype="submit"value="submit"></form>

You also should not be using window.location.href. This is very ugly. When you submit the form (click the submit button) it will POST your form data to script.asp.

Another way to submit your form is to submit it via DOM. document.forms[0].submit();

Post a Comment for "Window.location.href Using Get When I Need Post"