Lack of Ajax query string parameters

To implement a functionality where clicking on a delete button in the UI triggers a service method that retrieves data from a database and displays it in a popup, I need to call a specific method in an Action class. The task id and command name (method name) are added to the query string for this purpose. However, when trying to retrieve the command parameter using request.getParameter("command"), it returns null.

I am looking for a JavaScript method to handle this issue.

function ajaxGetDependentTask(id)
{
    try
    {
        xmlHttp = new ActiveXObject("Msxml2.XMLHTTP")  // For Old Microsoft Browsers
    }
    catch (e)
    {
        try
        {
            xmlHttp = new ActiveXObject("Microsoft.XMLHTTP")  // For Microsoft IE 6.0+
        }
        catch (e2)
        {
            xmlHttp = false   // No Browser accepts the XMLHTTP Object then false
        }
    }
    if (!xmlHttp && typeof XMLHttpRequest != 'undefined')
    {
        xmlHttp = new XMLHttpRequest();        //For Mozilla, Opera Browsers
    }
    var url = "/admin/TaskEdit.do?id=" + id + "&command=findDependenciesFor";
    xmlHttp.open("GET", url, true);
    xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    xmlHttp.onreadystatechange = handleServletResponse;
    xmlHttp.send();
}

The issue lies with the form submission process and the resulting query string being null.

Answer №1

If the form has been submitted, the request parameters received by your server will be based on the inputs within the form, not what is written here...

To handle this situation, it is recommended to utilize jQuery and create your own ajax call within the form.submit() function. Remember to add return false; to prevent the form from submitting automatically.

For a more convenient and cross-browser compatible solution, consider using jQuery ajax for sending the AJAX requests:

function fetchDependentTask(id){
  $.ajax({
    url: '/admin/TaskEdit.do',
    type: 'GET',
    data: {
      id: id,
      command: 'findDependenciesFor'
    },
    success: handleResponse,
    error: function(){console.log('An error occurred during the process');}
  });
}
$('#yourButtonId').on('click', function(){
  var id = $(this).val(); // Assuming this is how you retrieve the 'id' for your example code above...
  fetchDependentTask(id);
});
$('#yourFormId').submit(function(){return false;});

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

Using AngularJS to Send Elements to Scripts and Selectors

When I use the following template: <div id="container"> <textarea name="message"></textarea> <button value="send" ng-click="testMethod($parent)"> </div> In the JavaScript code: $scope.testMethod = function(element) ...

Use React Router to create a link that goes to the same URL but passes along unique state

Can someone help me figure out how to open the same URL using react-router Link while passing different state each time? <Link to={items.vehicleModelId === 2 ? '/ecgo-3' : items.vehicleModelId === 3 && '/ecgo-5' ...

Tips for choosing a text node that is a child of a span node

I am facing an issue with selecting the Active user with tag number 00015339 on my webpage. I am unable to write a correct xpath for it. What I really need is an xpath that can retrieve all Active users regardless of their tag numbers. Below is the code s ...

Is it possible to have Vue.js code within a v-for loop in such a way that it executes every time the v-for loop runs?

<div class="questions" v-for="(q,index) in questions " :key="index" {{this.idx+=1}} > <h3 > {{q.content}}</h3> <h3> A) {{q.a}} </h3> <h3> B) {q.b}} </h3> ...

Is p-queue designed to utilize multiple threads?

Have you heard of a nodejs module that allows you to limit the number of concurrent promises? Check out this link I'm curious, does this module utilize multiple threads? Here's an example taken from the official page: const {default: PQueue} ...

Sending data through props to components that can only be accessed through specific routes

File for Router Configuration import DomainAction from './components/domainaction/DomainAction.vue' ... { path: '/domainaction' , component: DomainAction }, ... Linking to Routes using Router Links ... <router-link to="/domainact ...

How to dynamically generate Angular component selectors with variables or loops?

Looking to dynamically generate the Selector Tag in my app.component.html using a variable. Let's say the variable name is: componentVar:string What I want in my app.component.html: <componentVar></componentVar> or <app-componentVar& ...

A Guide to Integrating Cloudinary Upload Widget in React

I am encountering an issue with the Cloudinary Upload Widget in my React App. The problem arises when I open and close the widget multiple times, causing the app to crash and display the error message: widget.open() is not a function Note: Despite this ...

Using Ajax to create a loading animation

I want to display an ajax-loader.gif while my data is loading, and then hide it once the data has been completely loaded. Here is the code snippet for update: $.ajax({ type: "POST", dataType: 'json', url: "api/Employee/GetData", beforeSend: fu ...

Transitioning from the Play mode to the Pause mode upon pressing the Set button

Is there a way to make the button switch from play to pause once the 'Set' button is clicked? Clicking on 'Set' should change the SVG to display the pause button icon. Snippet of Code: https://jsfiddle.net/192h0w85/195/ (function ...

You are only able to click the button once per day

I am working on a button that contains numeric values and updates a total number displayed on the page when clicked. I would like this button to only be clickable once per day, so that users cannot click it multiple times within a 24 hour period. Below i ...

A guide on updating the color of a Button component (Material UI) when dynamically disabling it

In a React table, I have a button that is disabled based on the value in an adjacent column. For example, if the value in the adjacent column is "Claimed", the button is disabled. However, if the value is "Failed" or blank, the button can be clicked. Curre ...

Method Not Allowed: The AngularJS AJAX request received an undefined 405 error

I’ve recently been experimenting with AngularJS and REST, but I keep running into an issue when trying to fetch data. I’m receiving the error message - undefined 405 (Method Not Allowed) In my main.js file: url:'http://abc.org/angularDemo/rest/d ...

What should the AJAX file in TagManager jQuery look like?

I'm currently utilizing Tagsmanager with JQuery, which can be found at There is a feature that allows tags to be pushed via Ajax: jQuery(".tm-input").tagsManager({ AjaxPush: '/ajax/countries/push', AjaxPushAllTags: true, ...

Ways to rejuvenate an angular component

I am in the process of developing a mobile application using ionic 4. The app supports two languages, namely ar and en. The menu drawer is a pre-built component included within the app. In order to ensure that the drawer component displays the correct sty ...

Creating compressed files using JavaScript

I am currently working on unzipping a file located in the directory "./Data/Engine/modules/xnc.zip" to the destination folder "./Data/Engine/modules/xnc". Once I have completed writing to these files, I will need an easy method to rezip them! While I wou ...

Every other time, Django's request.GET.get() method will return None

I am currently working on implementing AJAX requests to exchange data between Django views and templates. However, I have encountered a peculiar issue with the request.GET method in Django. I am receiving an error message stating that the data parameter ...

Using socket.io and express for real-time communication with WebSockets

I'm currently working on implementing socket.io with express and I utilized the express generator. However, I am facing an issue where I cannot see any logs in the console. Prior to writing this, I followed the highly upvoted solution provided by G ...

Building New Web Pages with Express in Node.JS

I want to dynamically generate a new page on Node.JS with Express upon user form submission. Here is my initial approach, but it's not working as expected: var app = require('express')(); var server= require('http').createServer(a ...