The forward button fails to function when clicked

I am trying to redirect or forward a page after making a $.ajax call

$(document).ready(function(){
$('#submit').on('click', function(){

    var params = "";
    $('#tableResultat > tbody > tr').each(function(){
        $parent = $(this);
        params += $parent.find('td:eq(0)').attr('id') + ","  + $parent.find('td:eq(0)').text() + "," +  $parent.find('td:eq(1)').text() + ","  + $parent.find('td:eq(2)').text() +','+ $parent.find('td:eq(3)').text() +"|";
    });

$.ajax({
    type: 'POST',
    url: '/resultat',
    data:{
            parametres : params
        }
}); 
});
});

On the server side, my code looks like this:

protected void doPost(HttpServletRequest req, HttpServletResponse resp)throws ServletException, IOException 
{
     String action = req.getServletPath();
     if(action.equals("/resultat"))
     {
         String params = req.getParameter("parametres");
        //save these value in DB 
         req.getRequestDispatcher("WEB-INF/vues/resultat.jsp").forward(req, resp);
         return;
     }   
}

I am facing an issue where clicking on my button does not redirect me to resultat.jsp. Can anyone help me with what I might be doing wrong?

Thank you for your responses

Answer №1

When using $.ajax calls, it is important to handle the response and perform actions based on it by utilizing a 'success' function.

In your scenario, I recommend returning the complete URL (including http://) and modifying your ajax request as follows:

$.ajax({
    type: 'POST',
    url: '/resultat',
    data:{
            parametres : params,
            success : function(response){
                window.location.href = response;
        }
}); 

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

Expanding and collapsing Javascript accordion when a new tab is opened

Is there a way to prevent previously opened accordions from remaining open when opening another accordion? Any help on fixing this issue would be greatly appreciated. Thank you! let acc = document.getElementsByClassName('ac-btn'); let i; fo ...

Is async/await necessary even if the outcome is not important to me?

Imagine I have an API call that performs X and I convert it into asynchronous code using async/await: export default async (req: NextApiRequest, res: NextApiResponse) => { let success = await sendEmail({ //... }); return res.status(200) ...

Switch between active tabs (Typescript)

I am working with an array of tabs and here is the code snippet: const navTabs: ITab[] = [ { Name: allTab, Icon: 'gs-all', Selected: true }, { Name: sources.corporateResources, Icon: 'gs-resources', Selected: false }, { Name ...

preventing users from selecting past dates on Full Calendar Plugin

Is there a way to disable the previous month button on the full calendar? Currently it is April. When I click on the previous button, the calendar shows March instead of disabling. How can this be prevented? http://jsfiddle.net/6enYL/ $(document).ready( ...

The function assigned to [variable].onclick is not being executed, despite no errors being displayed in the console

I'm new to javascript and I'm looking for help with a simple task. I want to create a code that when clicking on an image, it will open in a modal. This feature is important for viewing full-size images on my portfolio. Although there are no erro ...

Ways to run scripts or commands during the installation process of my Electron JS software on different operating systems

I have completed a project using electron js and now I am looking to create a Linux distributable with electron forge make. However, during the installation of this software on a Linux system, users need to execute the following command: sudo sed -i ' ...

Keeping Ajax active while the PHP script is running is essential

Seeking assistance with a specific issue. I currently have an ajax script (index.php) that sends variables to a php file (thumbs.php). The php file generates thumbnail images from original files and saves them on the server. This process can sometime ...

Avoid receiving input for a button that is being covered by another button

I am currently developing an Idle Game and I am looking to include 'buy buttons' for purchasing buildings, along with a sell button embedded within the buy button. Just as a heads up, these buttons are represented by DIVs acting as buttons. Here ...

Combining two arrays with varying lengths based on their values

Seeking assistance with a programming task that is straightforward yet challenging for me. There are two arrays: one long and one short. var arrayShort = [ { id: 'A', name: 'first' },{ id: 'B', name: &ap ...

Passing parameters between various components in a React application

Is it possible to pass a parameter or variable to a different component in React with react-router 3.0.0? For example, if a button is clicked and its onClick function redirects to another component where the variable should be instantly loaded to display a ...

The use of Next.js v12 middleware is incompatible with both node-fetch and axios

I am facing an issue while developing a middleware that fetches user data from an external endpoint using Axios. Surprisingly, Axios is not functioning properly within the middleware. Below is the error message I encountered when using node-fetch: Module b ...

Guide on adjusting the value for a Bootstrap slider

Using the bootstrap slider, I am trying to configure a way to assign a value to the handle from another variable. Although I came across a method that uses the data-slider-value attribute for this purpose, it did not work for me. <input id="gravite" na ...

jQuery: Modifying the Style of obj "th" Element

I am looking to update the style of my selection using jQuery. After using this module to retrieve all items, I have a list of cells with new coordinates. //cell list with new coordinates cl = Object {0-0: th, 0-1: th, 0-2: th, 0-3: th, 1-0: td…}, id = ...

The topic at hand pertains to a specific exercise featured in the well-known book Eloquent JavaScript

In this exercise, the final step is to create a recursive function that takes a joined list and an index as parameters. The function's purpose is to find the value in the object within the list at the specified index. The code I have written seems to ...

The Express server is failing to deliver a response to the client when using the fetch method

Currently, I am utilizing express for the server side of my project. To send a post request from the client to the server, I am using fetch. The data that I am sending to the server is being successfully transmitted and displayed. However, I am encounteri ...

Customizing Magnific Popup: Changing showCloseBtn and closeOnBgClick settings during display

Is there a way to customize the behavior of an open instance of a magnific popup? I want to have different settings for when the popup is closable and when it should be prevented from closing. It appears that these options are only available during initial ...

Inject nested controller dynamically

I am working on a straightforward ASP.NET MVC application that includes an ng-controller. I am trying to inject another ng-controller inside this controller using a partial view, but I'm having trouble getting the binding to work correctly. You can s ...

Vue.js is prevented by Content-Security-Policy

Running a HTML page on my node.js server with express.public() function. I included the following in my html page: <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script> However, Chrome gave me a Content-Security-Pol ...

What is the method to retrieve text from a div element with Webdriver-IO?

Is there a way to extract the value from the following HTML element using Webdriver-IO for automated testing? <div class="metric-value ng-binding" ng-style="{'font-size': vis.params.fontSize+'pt'}" style="font-size: 60 ...

Issue when activating Materialize Bootstrap

I'm facing an issue with my code. I have implemented a feature where a modal should be triggered after a user successfully adds a new user. However, I am using Materialize and the modal is not being triggered. Below is a snippet of my code: <div i ...