Concealing query strings within JavaScript using the Post method

Below is the JavaScript code I am using:

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

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

Every time the page redirects to the SavedDataSet_edit.aspx page, the query string is displayed in the address bar of the browser.

How can I hide the query string? And if I hide it from the browser, how do I fetch it on the SavedDataSet_edit.aspx page?

Thank you.

Answer №1

There are multiple methods to accomplish this task. One option is using cookies, although it may not be the most recommended approach. Another way is to post to a hidden field on your page and then retrieve it using the FormCollection property of the Request object. To post to your page dynamically, you would need to create a form that is then submitted. Here is an example of how the code could look:

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");

Answer №2

To keep it concealed, transfer the data to SavedDataSet_edit.aspx, save it in session, and then have the page redirect back to itself without displaying the querystring. Another option is to insert a different page between the two to securely store the information in session. Alternatively, you can encrypt the value and pass an encrypted querystring, ensuring that the data originates from the server.

Regardless of the method chosen, always verify the user's permissions on the resource to ensure they are authorized to access it.

Answer №3

window.location.replace function does not support POST requests, therefore it is unable to send POST data. In this case, you have a few options available:

  1. Continue using the query string method and accept that the value will be visible in the URL, although this may not be ideal.
  2. Transfer the query string data into a form and submit the form as outlined in responses from guidance on passing post data using window.location.href.
  3. Utilize the existing AJAX call to createDataSet.aspx and save the desired value for retrieval on the SavedDataSet_edit.aspx page by storing the businessId data in a session during your time in createDataSet.aspx. Then, access and retrieve it from the session cache during the Page_Load of SaveDataSet_edit.aspx.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is the best way to position a point slightly off the data points on the axis in ECharts?

I'm not sure if my English is correct, but I really need some assistance. Do you have the necessary data for an Echart graph? option = { xAxis: { data: ['A', 'B' 'B', 'C', 'D', 'E'] ...

How can I use jQuery to wrap multiple elements into separate divs simultaneously?

Is there a way to wrap elements individually with jQuery? I am able to wrap different divs, but they all end up wrapped in one parent div instead of separate ones. This is what I currently have: <section> <div class='parent'> ...

What is the best way to customize the styles of a reusable component in Angular2?

I am working with a reusable component called "two-column-layout-wrapper" that has its styles defined in the main .css file. In another module, I need to use this component but customize the width of two classes. How can I override these styles? import ...

Using Golang to encode JSON for parsing in JavaScript

I am working with a struct that looks like this: type User struct { Login string `json:",string"` PasswordNonce Nonce `json:",string"` PasswordHash HashValue `json:",string"` CreatedOn time.Time `json:",string"` Email ...

Assign the JSON response to a variable and then display it

I am currently working on a form that sends a combination of Zip code and house number to an external page. The external page then responds with a JSON containing address information. Although the process is functional, I am struggling to figure out how t ...

Encountering CORS Error while trying to access Guest App in Virtualbox using Vue, Express, and Axios

I encountered an issue while trying to access my Vue app in Virtualbox from the host, both running on Linux Mint 20. Although I can now reach the login page from my host, I am consistently faced with a CORS error during login attempts: Cross-Origin Request ...

Is there a way to use JQuery/AJAX to extract the selected values from all drop-down menus within a designated container?

With the help of JavaScript, I am dynamically creating dropdown lists under dvContainer. My goal is to retrieve the selected values of all select elements within that container. Below is the HTML code generated through JavaScript: <div id="dvContai ...

Uncovering the "parent having two child elements" structure from HTML: A guide

I want to identify all parents with two children in an HTML document. Case 1 <parent> <child> <tag></tag> </child> <child></child> </parent> Case 2 <parent> <parent_and_child> <tag& ...

What is the best way to conceal a modal using jquery?

Click button to open modal: <button type="button" class="btn" onclick="CountClass()" runat="server" data-toggle="modal" data-target="#inlineForm1">OPEN</button> The modal code: <div class="modal fade text-left" id="inlineForm1" tabindex=" ...

updating database using AJAX requests

My attempts to input data into a database have been inconsistent. Around 80% of the time, the process works smoothly and I can see the new data in the database. However, there are instances where it seems like the script fails to execute. This is the ajax ...

Jquery Ajax is met with a 400 error indicating a BAD request

I've encountered an issue while trying to send data to my local DB server. Every time I attempt to send the data, I keep receiving a 400 Bad Request error. var studentEmail = "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail ...

After a refresh, jQuery's mousenter event is not functioning

I am currently working on a fun project called Etch-a-Sketch for The Odin Project, and I have a jquery grid that can be redrawn with the click of a button. Initially, the grid allows the user to choose the size and then draw on it using .mouseenter. Howev ...

What could be causing this issue with the ng-bind and ng-show directives not functioning as expected?

Attempting to show data retrieved from Google's Place Service. Oddly enough, the object can be logged to the console within the controller, but the directives in the HTML file remain blank. Since no map is being used, a div element was passed as the n ...

What are the reasons for validation failure when it is moved into a method?

I am currently in the process of developing a validation function in JavaScript. However, when I extracted the logic into a private method, my validation started failing and I can't seem to figure out why. Here is my HTML definition: <input type= ...

error message: "required assembly reference not found"

Similar Issue : missing assembly reference Hello all, I am in need of assistance I have provided the code for my Shopping.cs file below using System; using System.Data; using MyWebsite.Commerce; using System.Collections.Generic; using System.Configurati ...

Preventing a JavaScript function from executing multiple times

Having only recently started learning javascript and jquery, I encountered a problem where one of my functions kept executing itself when calling another function. Despite trying various solutions found here, the function either stopped executing altogethe ...

I am facing an issue where my component template is unable to locate the value property specified in the <script> section of VueJS

My app seems to be having trouble reading the value variable that I defined in the data section. It's strange because Npm compiles everything without throwing any errors. If you want to take a look at my code, here's the fiddle link: https://js ...

Is there a way to utilize JavaScript to access and read an array of data from a local JSON file

I need to load a .json file into a global variable that can be accessed across all web pages using AJAX and JavaScript. How can I achieve this? I want to retrieve values from the variable using an index, like accessing my_var[1].img. Despite searching thro ...

Javascript did not provide any prompt

I can't seem to get the function to run when I click the link, it only takes me to the link address. (The final alert() function is not executing). I really need that alert message, what am I missing? Below is my code: <html> <head> ...

Is there a way to stop users from altering form values on a webpage by using the "inspect" tool in their browser?

Currently, I am developing an application using node.js and handlebars as the view engine. One issue I am facing is that when a form is submitted, it inserts data into the database. The problem arises because the form passes values that are hidden from the ...