The last ajax call in a Spring application is triggered after the user logs in

Lately, I've been encountering a major issue in my application.

Whenever I search for a value in the application and my session has expired, the application correctly redirects me to the login page.

However, upon logging back in, instead of being directed to the home page, the application displays the results of the last GET ajax call that I made along with the resultant JSON on the browser.

The code snippet I am working with is shown below;

// Document Ready() Starts

$("#grid_id").jqGrid({
                url :"search/getHouseholdHistoryList",
                async : false,
                type: 'GET',
                datatype: 'json',
                postData: {
                    searchHHID: function() { return $("#txt_SearchID").val(); },
                    filterKey:  function() { return $('#ulSearch_TypeOfID li.selected').attr('value') }
                },
                colNames:mainGridColNames,
                colModel: [
                    { name:'incidentID', index:'incidentID', width:110,sortable:true},
                    { name:'incidentCreatedDate', index:'incidentCreatedDate', width:160, sortable:false},
                    { name:'incidentSummary', index:'incidentSummary', width:482,sortable:false},
                    { name:'incidentStatus', index:'incidentStatus', width:120, sortable:false},
                    { name:'actionLink', index:'actionLink', width:100, sortable:false}
                ],
                viewrecords: true,
                //autowidth:true,
                width: '100%',
                height:'150',
                rowNum: 10,
                rowList:[10,20,30], 
                rownumbers: false,
                sortorder: "desc",
                ignoreCase: true,
                loadonce: true,
                jsonReader: { repeatitems: false },
                pager: 'gridpager',
                direction:'ltr'
            }).jqGrid('navGrid','gridpager',
                      {edit:false, add:false, del:false, search:true, refresh:true});

//Document Ready() Ends

I'm utilizing -Spring MVC. -JSP -jQuery -Ajax

Please advise if any additional information is needed.

Answer №1

It seems like the issue arises when attempting to send your ajax request from a session that has expired while viewing your application. When you access the protected "search/getHouseholdHistoryList" endpoint, Spring Security triggers a login prompt before displaying the requested information. Unfortunately, it does not retain any previous session data after expiration, resulting in only the raw results being sent back to your browser.

To prevent this inconvenience, it is recommended to validate the session's status before making the request and redirecting the page to the login screen if necessary. While I may not be well-versed in Spring Security JSP tags due to my limited use of JSP, there should be a function available to verify the current session's validity and handle it accordingly.

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

Updating the Name of a String Variable in a For Loop

I'm trying to find a way to change the name of a string variable named "str" within a for loop. Here's what I have in mind: for(int i = 0; i <= 5; i++) { //add i to end of string name } This way, the string's name would evo ...

How can I pass the current value of an HTML.DropDownListFor to an ActionLink?

Is it feasible to transfer the current value of @Html.DropDownListFor to an action link? I am trying to send the template value to the Sample controller using the Create action. The code below is not functioning because @Model.SurveyTemplate does not retur ...

View is unable to trigger the success attribute

Currently, I am delving deep into Backbone JS and facing an issue where the 'success' function in 'EditUser' is not being triggered. I would greatly appreciate it if someone could guide me on what changes I need to make in the code? B ...

"Implementing a click event on a dynamically generated element is triggering the event for all of its parent elements

I have a task to generate a dynamic table with data retrieved from the server. Each row in the table contains a tag that I am trying to link to a click event. The code snippet below demonstrates how the dynamic table is created: function ProcessResponse ...

Encountering issues in transmitting form data to a Node server from Angular

In my Angular application, I am working on creating a registration page with validation. Once the user fills out the form and submits it, the data is sent to the server and saved in MongoDB. This is the approach I have taken: register_user() { const ...

attempting to link to an external style sheet hosted on Amazon S3

I am working on creating a widget or snippet of a website that can easily be added to another webpage by including a script tag for my JavaScript file hosted on Amazon S3 and a div element where content will be inserted. Even though I have uploaded the C ...

javascript ajax if statement is returning a false value erroneously

Upon successfully connecting and receiving data from PHP using AJAX, I encountered an issue with my if statement returning false inexplicably... Javascript: var xhr = new XMLHttpRequest(); xhr.open('POST', action, true); xhr.setRequestHeader(&a ...

Error message consistently pops up when using the jQuery search feature

My jQuery function is fetching data from a different domain, and I want to use AJAX to display that data when the user enters a value into the search box. However, no matter if I search by .productName or .itemCode, the app always gives me an error messa ...

Enhance the code for updating the content within a div element

I recently discovered that utilizing jQuery allows for updating the content within a div. My goal now is to enhance this script so the content remains consistent, even while loading or not. Take a look at my current code: function changeContent () { va ...

Modifying element size using jQuery causes issues with maintaining a 100% height

I am facing an issue with a sidebar that is styled using the following css properties: background:#164272; position:absolute; left:0px; top:70px; width:250px; height:100%; When I use jQuery to display a table that is initially hidden and on ...

Leverage environment variables within your index.html file

Currently, I am using Angular and I am encountering an issue while attempting to utilize an environment variable in my index.html for Google Analytics. I have attempted the following approach: <script> import {environment} from "./environments/e ...

What could be causing my gradle build to run so slowly?

I'm working on an app with an APK size of 28 MB and I need to reduce the installation time. When testing on the emulator, it takes 5-7 minutes, but when testing on a device, it's taking more than 10 minutes. Any suggestions for speeding up the p ...

Transform identical words in a website's content into clickable buttons

I'm currently in the process of developing a Chrome extension that scans a website for specific keywords and then converts them into interactive buttons. However, I've encountered an issue where changing the text causes the image path to become c ...

Guide for displaying and hiding an image using a button or link in Next.js

I'm a beginner with React and Next.js, and I have the following code snippet: import Link from 'next/link'; import Image from 'next/image'; async function getPokedex() { const response = await fetch(`http://localhost:3000/api/p ...

Are there any unique purposes for _id in MongoDB?

I have a nodejs application that defines answers like this: var answerSchema = mongoose.Schema({ session : String, // the ID of the session question : String, // the ID of the question answer : Number // the selected answer (1-5) }); whic ...

Struggling to upload files using multer in Node.js?

Currently attempting to implement a feature where multiple files can be uploaded using a modal that includes a form with an input field. Here is the structure of my modal (in jade template format): #modalAddFile.modal form#uploadForm(enctype='mu ...

Converting JSON data to DateTime format - modifying the layout

When sending a string date in the format of "dd/mm/yyyy" from JavaScript (with JSON) to the server (C#), I am encountering an issue where C# DateTime returns null. However, if I send the date in the format of "mm/dd/yyyy", it works fine. I am using MVC4. ...

Tips for adding multiple instances of objects to an ArrayList

After adding the details of a Person twice to an ArrayList, I noticed that when I try to print both objects, only the final details are repeated twice while the first set is not printed at all. import java.util.ArrayList; public class Arraylist { Per ...

What is the best way to show both the input and output on one page?

I have a single PHP file with two separate PHP tags. When I click on the first row in the table of the first PHP tag, I want to display the value of the first row in the table of the second PHP tag on the same page. The common field for both tables is or ...

Accurate date and time depiction at a high resolution using JSON and JavaScript

Is there a standardized method for displaying high-resolution timestamps in JSON and/or JavaScript? It would be ideal to have support for at least 100 ns resolution, as it would simplify the server code (due to the 100 ns resolution of the .NET ...