Transferring a JavaScript variable to JSP using AJAX

I'm struggling to figure out the correct syntax to pass a JavaScript variable named "textVal" to a jsp file. Here is my code snippet:

 function show(textVal){
   AJAX.onreadystatechange = handler;
   AJAX.open("POST","service.jsp",true);
   AJAX.setRequestHeader("Content-type","application/x-www-form-urlencoded");
   AJAX.send("fname='+textVal+'");
};

Can someone help me with passing the textVal variable to service.jsp?

Answer №1

It is unnecessary to include additional quotation marks. The following syntax can be utilized:

AJAX.send("fname="+encodeURIComponent(textVal));

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

Concentrate on a specific input within a list of inputs that are generated dynamically

My list contains dynamically generated inputs. input --> onClick new Input beneath [dynamically added]input input How can I focus on just the dynamically added input? The input has the textInput reference. This code partially achieves it: componentW ...

What is the process for retrieving the date and time a location was added to Google Maps?

My goal is to extract the date and time a location pin was added in Google Maps. For example, if I search for McDonald's in a specific area, I want to retrieve the dates and times of all McDonald's locations in that area. Is there a method to acc ...

Tips for specifying minimum length in the v-autocomplete component in Vuetify

Within my code, I incorporate the v-autocomplete UI Component. Is there a way to configure it so that it only starts searching after a minimum length of 3 symbols? Typically, the default minimum length is set to 1 symbol, and it shows the no-data-text mes ...

AJAX Form Submission for CommentingAJAX allows for seamless form submission

Currently facing an issue with a form submission that is not displaying comments without refreshing the page. When the submit button is clicked, it redirects to the top of the page without executing any actions - no insertion into the database and subseque ...

dc.js bar graph bars blending together

This datetime barChart is causing me some trouble. Interestingly, when I try to replicate the issue in a fiddle (check here), everything functions as expected. Please note that the data takes about 30 seconds to load from github. Below is the code for the ...

Navigating an Ajax request using the .load() method in a Rails application

I am trying to implement an Ajax call that will render the content within my show action on the index page after clicking a link. Currently, I am using jQuery's .load() method for this purpose. However, I have run into an issue where the assets are be ...

"Securing Your Web Application with Customized HTTP Headers

I'm currently working on setting up a POST request to a REST API (Cloudsight) with basic authorization. Here is the code I have so far: var xhr = new XMLHttpRequest(); xhr.open("POST", "http://api.cloudsightapi.com/image_requests", true); xhr.setRequ ...

What is the best way to display an image and text side by side within a single row in react-table?

I am trying to display an image and text side by side within a single column in a React table. I have successfully added two texts together in a single column using the code below: Header: "Name", id: "User", accessor: (d) => ...

What is the best way to align a TabPanel component at the center using React Material UI

As I attempt to compile a list of articles while switching to a list of other entities in React + material UI, I have encountered some difficulties. Specifically, I am struggling to center the Card displaying an article in alignment with the centered Tabs. ...

Playing audio from local blob data is not supported on mobile browsers

I'm trying to stream blob data in mp3 format, but I'm experiencing difficulties with mobile browsers. The code below works perfectly on PC browsers, but not on mobile: // Javascript var url = URL.createObjectURL(blob); audio = document.getEleme ...

Navigating through JSON data to retrieve specific values and executing repetitive actions

When the form is submitted, I am making an AJAX request to PHP code and this is the response I receive. var data = { "empty":{ "game_sais_no":"Season cannot contain empty value", "game_sc_no":"Category cannot contain empty value", ...

Gather information from users using Node.js and integrate it with Stripe

As I am new to Node.js, my goal is to utilize nodejs & Stripe to gather user data such as name, phone number, email, city, etc. This way, I can easily identify the user from the Stripe dashboard along with all their corresponding information. on the server ...

Control the scope value using an AngularJS directive

I have a model with values that I need to modify before presenting them to the user. I have checked the documentation but might be overlooking something. For example, I would like to format my variable in this way: <span decode-directive>{{variable ...

Generating an associative array in PHP using AJAX with JQUERY

Seeking assistance for the first time here. I'm struggling to find a suitable title, but it's all I can think of at the moment. I've been working on this for 2 days now and have read so many things that I feel completely lost. I'll try ...

Unable to run the JSON.parse() function while using the 1.10.2 version of jquery.min.js

Has anyone else encountered a situation where using JSON.parse() to parse the PHP array return only works when applying 1.3.2/jquery.min.js and not 1.10.2/jquery.min.js? If so, what solution did you find? PHP array return $returnArray['vercode' ...

Encountering an Issue with NextJS on GAE: EROFS Error indicating a read-only file system

Trying to deploy a customized Next.js application into Google App Engine has hit a snag. The project runs smoothly locally and on Google Cloud Platform CLI, but upon successful deployment using gcloud app deploy, an error arises when opening the app. 2020 ...

Retrieve the Data from Input Fields with Matching Classes and Transmit to a Script Using AJAX Request

I am working on a form that includes multiple input fields: <input type="text" class="date" name="date[]" onkeyup="showHint()" /> <input type="text" class="date" name="date[]" onkeyup="showHint()" /> <input type="text" class="date" name="da ...

Creating identical dropdown filter options from API in React.js

My dropdown menu is experiencing an issue where it is showing duplicated values from the API. When I receive documents from the backend, some of them have the same name, resulting in duplication in my dropdown list. Here is a snippet of my code: The funct ...

An unusual 'GET' request has been made to the '/json/version' endpoint in Express.js

Hey there, I'm facing a challenge with my Express project. For some reason, I keep receiving a 404 error due to a mysterious GET request to '/json/version'. The request seems to bypass the defined routers after adding session data and eventu ...

Is it possible to integrate Processing JS on top of an HTML element?

I have currently integrated Processing JS with the HTML canvas element on a website. The goal is to have the Processing JS animation run smoothly over the existing HTML elements on the page. You can check out the site at [usandthings.com][1] to get an idea ...