ghanshyam.mirani
ghanshyam.mirani

Reputation: 3101

Hide querystring in javascriptPost Method

I have following javascript :

  var link = AjaxLocation + "/createDataSet.aspx";
    $j.post(link, null, function() {
        window.location.replace("/admin/SavedDataSet_edit.aspx?businessId="+data);
    }, "html");

createDataSet.aspx page returns businessId for SavedDataSet_edit.aspx page...

whenever page redirect to SavedDataSet_edit.aspx page, querystring displays in the addressbar of the browser.

how to hide Querystring ?? and if i hide querystring from the browser then how to fetch it in the SavedDataSet_edit.aspx page??

Thanks..

Upvotes: 1

Views: 245

Answers (3)

Alexandr Mihalciuc
Alexandr Mihalciuc

Reputation: 2577

There are a number of ways to achive that: you can use cookies(I wouldn't recommend) you can post to our page hidden field and then retrieve it using FormCollection property of the Request object. To post to your page you would need to craete dynamically a form that then submit it, the code would look like:

var link = AjaxLocation + "/createDataSet.aspx";
    $j.post(link, null, function() {

        $("<form action='/admin/SavedDataSet_edit.aspx'><input name='businessId' type='hidden' value='"+ data +"'></form>").appendTo('body').submit();


    }, "html");

Upvotes: 1

Karl Anderson
Karl Anderson

Reputation: 34844

window.location.replace is not a POST request, so it cannot send POST data. So your choices are:

  1. Keep using the query string route and just live with the value showing, sounds like this is not a realistic option though
  2. Put the query string data into a form and submit the form as described in various answers to pass post data with window.location.href.
  3. Leverage the AJAX call you are already making to createDataSet.aspx and store the value you want to retrieve on SavedDataSet_edit.aspx page by storing the businessId data in Session when you are in the createDataSet.aspx and then retrieving it from Session cache when you are in the Page_Load of SaveDataSet_edit.aspx.

Upvotes: 0

Brian Mains
Brian Mains

Reputation: 50728

The only way to hide it is to pass it to SavedDataSet_edit.aspx, store it in session, then have that page redirect to itself without the querystring. Or use a different page in-between the two to save in session. Or, you could encrypt the value and pass encrypted querystring, provided data is a value coming from the server.

Make sure, even though you may do that, to check permissions on the resource to see that the user is authorized.

Upvotes: 0

Related Questions