The execution of consecutive Ajax requests encounters issues in the Google Chrome and Safari browsers

I am facing an issue where I encounter a problem displaying a sequence of dialogue or AJAX results that depend on each other. For instance, when a user clicks to send a message, it triggers an ajax call, which opens a dialogue box. The user fills out the form and submits it via AJAX, causing the dialogue to close. Then, another AJAX response either opens another dialogue or redirects the user. This process works smoothly in all browsers except for Safari and Chrome. Interestingly, it used to work fine previously in all browsers, but now it seems to be failing. The error function is triggered, and the browser eventually opens the URL that was used for the second AJAX request.

My implementation involves using jquery, PHP, and JavaScript. Initially, I had it set up to run from an eval(json) command. However, I have since rewritten the code to return raw JavaScript.

In any case, the error occurs in the 'error' handler of the AJAX query. The error messages returned are not very informative. I am aware that Chrome has a caching process, but I'm unsure if this affects the situation or if it exists in Safari. Nevertheless, it appears that the second AJAX call fails in Safari and Chrome before the returned JavaScript is executed. I remember it working flawlessly in all browsers before, but I'm no longer confident about that. I've already spent almost half a day trying to figure it out, so I would greatly appreciate some assistance. :D

The JavaScript function responsible for making the AJAX call is as follows:

function page(url){
     $.ajax({
            type: "POST",
            url: url,
            success : ajaxReturn,
            cache: false,
            dataType: 'script',
            error: function(result, status, err) {
                alert('HTTP ' + result.status + ' Error Encountered: ' + result.statusText);
                alert(result.responseText);
                alert('status: '+status+' error: '+err);
            return;
            }
        });

}

function ajaxReturn(ret){   
    eval(ret);
    $.unblockUI();
}

This is the same code used for both AJAX calls. In some cases, such as when an error is found in the form, the returned code is almost exactly the same. I have a well-established system for handling all dialogues, AJAX requests, and associated processes, which has been working perfectly until now.

The messages that are returned by the error handler are:

HTTP 0 Errpr Encountered: error

Followed by:

<null>

And then:

status:error error:

These messages are displayed using the alert statement. The element indicates an empty dialogue box. Therefore, despite running the same ajax functions and returning the same code, Chrome and Safari are encountering issues with the second call. Regardless of what is returned, they fail at the error handler, leaving me completely puzzled about the cause.

Answer №1

After a thorough investigation, I managed to identify and resolve the issues. It turns out that the content of the form within the dialogue was submitted through an AJAX call separate from the main process. To accomplish this, I used jQuery to serialize the form content before sending it off via AJAX. However, I made the mistake of not including a return false statement after the AJAX call in the onsubmit handler. As a result, when using Chrome or Safari, the error status would be returned as 0, and I would be redirected to the page called via AJAX.

Fortunately, adding a simple return false statement fixed the problem. It's such a relief!

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

Creating a continuous loop animation with CSS hover state

This piece of code creates an interesting effect when the text is hovered over. The slight shakiness adds a cool touch to it. However, this effect only occurs when the mouse is moved slowly; if the mouse remains stationary, the hover style takes precedence ...

Spinning html/css content using JavaScript

Greetings! I am currently working on a demo site using just HTML, CSS, and JavaScript. Typically, I would use Ruby and render partials to handle this issue, but I wanted to challenge myself with JavaScript practice. So far, I have created a code block that ...

The Google reCaptcha reply was "Uncaught (in promise) null"

When using reCaptcha v2, I encountered an issue in the developer console showing Uncaught (in promise) null message regardless of moving the .reset() function. Here is the console output: https://i.stack.imgur.com/l24dC.png This is my code for reCaptcha ...

Encountering issues with implementing router.push in Reactjs

Currently, I am working on ReactJS and utilizing Next.js. My current task involves refreshing the page (using routes), but I encountered an error message stating: Error: No router instance found. You should only use "next/router" inside the client-side of ...

How can I fetch data from SQL using JavaScript based on a specific value in PHP?

My application is built using the Yii2 framework. Within my application, there is a view.php file that consists of an element and a button. The element, <div id="userId">, contains the user's login ID, and I aim to use the button to re ...

How to use jQuery to update a text input field based on a selected <select> dropdown option

Hi there, I could really use some help with this issue... Here's the problem - I need to change the value of a textbox within a table based on the selection of an option in a dropdown. Here's a simplified version of what I mean: <select id= ...

Setting maxFontSizeMultiplier for all Text components

Is there a way to apply the prop maxFontSizeMultiplier={1} to all instances of <Text/> in my app without the need for a custom component? ...

Node.js (npm) is still unable to locate python despite setting %PYTHON% beforehand

Trying to get Node.js to work is proving to be more challenging than expected! Despite having two versions of Python on my computer, it seems that Node.js only works with the older version, 2.7. When I encountered an error, it prompted me to set the path ...

JavaScript: Controlling the ability to enter text based on the chosen option from a drop-down menu

After struggling to make my code work, I decided to create a piece of JavaScript to disable a text input when "Cash" payment is selected from the dropdown menu. On the contrary, I aimed to enable the text input if "Credit Card" payment was chosen. Unfortun ...

Replace the indexOf() method to be called on a null value

I have discovered a way to override functions in JavaScript, such as indexOf(), like this: var indexOf = String.prototype.indexOf; String.prototype.indexOf = function(){ //MY CUSTOM CODE HERE return indexOf.call(this, arguments); }; By doing this ...

Activate the clicked tab in the Bootstrap navbar when selected

I have gone through similar posts, but I am unable to get mine to work. My goal is to activate the clicked tab. Here is what my bootstrap navbar looks like in HTML: <div class="navbar navbar-default" role="navigation"> <div class="container" ...

Interactive Bar chart updates in real-time with Highcharts and AngularJs

With the help of a sample from Highcharts (here), I successfully integrated a bar chart into AngularJs. Below is the HTML code: <!DOCTYPE html> <html ng-lang="en" ng-app="myModule"> <head> <meta charset="ISO-8859-1"> <script sr ...

Execute unit tests for the nodejs project

Looking to execute the tests for this project on GitHub? Head over to the test folder on https://github.com/node-opcua/node-opcua. However, I'm unsure about the testing framework that was utilized and how to run all the tests. Any guidance would be mu ...

Transfer the cropped image to the database through AJAX on the client side and PHP on the server side

I am attempting to upload an image to a Database using JavaScript on the client-side and PHP on the server-side. The first step is selecting an image from the gallery. After zooming and cropping the image, it should be passed to the database. The issue ...

Conditions in Apache mod_rewrite

Having trouble with Apache's module rewrite (creating browser-friendly URLs). My goal is to redirect every request to a specific PHP document if it contains a certain string: RewriteBase /folder/directory/ RewriteCond %{REQUEST_FILENAME} !-f RewriteC ...

Limiting the size of image uploads in AWS S3

Currently, I am attempting to go through the steps outlined in this repo, which involves utilizing nextjs and AWS S3 for image uploading. However, one thing that is puzzling me is the limitation of 1MB on image sizes. I'm curious as to why this restri ...

retrieving a date from a different source and displaying it in a date

Is there a way to ensure that the date format in an input of type date always follows the dd/MM/yyyy Brazilian pattern, regardless of the computer or browser specifications? <div class="input-group input-group text-center in ...

Utilize jQuery to swiftly align elements within a designated container

Check out my JSFiddle example: http://jsfiddle.net/c62rsff3/ I'm attempting to implement snapping behavior between 2 elements using this code: $('.draggable-elements').draggable({ snap: true }); In addition, I've defined a container ...

Retrieve JSON data and use a button to sort and display markers on a Google Map

Is it possible to modify my function in order to use different PHP files with separate buttons without duplicating the code? Currently, I have a function that displays markers on an external HTML page when a button is clicked. The data is retrieved from fi ...

AngularJS returns an empty array following a get request

Upon sending a GET request in my code example to retrieve a response array containing data, I noticed that the array appears empty in the console of Firefox. I am uncertain about where the error might be occurring. https://i.stack.imgur.com/aRWL9.jpg Belo ...