blazinazian
blazinazian

Reputation: 305

Redirecting using location.href

I am trying to redirect a user to a different asp page with some data that the asp page can use. This is the code I am using:

var done = confirm("Would you like to save?");
if (done == true)
{
    var concode = "<%response.write(concode) %>";
    location.href = "Main.asp?concode="+concode;
}

However I am noticing that information is showing in the URL after "Main.asp?concode=" which is similar to a html form "get" method.

Is there any way I can make this code similar to a html form "post" metod? Because I am using a <%request.form("concode")%> and there is information in the URL that is sensitive, such as the server name and password.

Or do I have to use a combination of AJAX and javascript to achieve what I need?

Upvotes: 1

Views: 250

Answers (2)

Jon Hanna
Jon Hanna

Reputation: 113272

The easiest way to post data from javascript and move the page to the results (rather than using AJAX to do so without changing the page) is to put that information into a form, and then submit() it. The form can be hidden, or consist entirely of inputs with type="hidden" so it need not affect the UI.

That said, the only added security from this is of over-the-shoulder reading. Important, but it still needs HTTPS to protect it from eavesdroppers (and it won't protect anything from the user themselves, anything that the end-user shouldn't be allowed to see simply can't be dealt with through javascript).

Upvotes: 1

Kristof Claes
Kristof Claes

Reputation: 10941

You are correct. What you are saying is "Hey browser, go to this URL with this querystring" and that is indeed a GET request. If you want to use a POST request, you will indeed need some JavaScript and AJAX. For example the AJAX POST features in jQuery: http://api.jquery.com/jQuery.post/

Upvotes: 1

Related Questions