Internet Explorer 9 terminates POST requests using XDomainRequest

I have been implementing a cross-domain Ajax call in my project.

Here is the code snippet I used:

if (window.XDomainRequest) // Checking if XDR is supported by the browser.
{
    xdr = new XDomainRequest(); // Creating a new XDR object.
    if (xdr) {
        xdr.timeout = 3000; // Setting timeout to 3 seconds.
        xdr.onload = function () {
            alert("Success");
        };
        xdr.onerror = function () {
            alert("Error");
        };
        xdr.ontimeout = function () {
            alert("Error");
        };
        xdr.open("post", urlSearch);
        xdr.send();
    }
}
else {
    $.ajax({
        url: urlSearch,
        type: 'POST',
        dataType: 'json',
        timeout: 3000,
        success: function (data) {
            alert("Success");
        },
        error: function () {
            alert("Error");
        }
    });
}

The code works well on most browsers, but in IE, it sometimes shows an error with "(aborted)" message.

To resolve this issue, I tried searching for solutions online but couldn't find any promising ones.

You can view the error message displaying "(aborted)" here.

Individual calls to specific URLs don't show the "(aborted)" message and display the Success alert instead. However, when making multiple calls (as shown in the image), the error occurs.

If you have any suggestions on overcoming this issue, please feel free to share them with me.

Thank you for your assistance.

Answer №1

It seems like I encountered a similar issue where I had to set the following event handlers: onerror, onprogress, ontimeout, and onload in my case. Here are some resources that discuss this problem:

Various other sources also offer solutions but can be conflicting at times. One suggestion involved wrapping the xdr.send call in a setTimeout function.

In my case, the issue was resolved by providing non-blank bodies for each event handler function. It's uncertain if all of them are required, as adding a setTimeout wrapper was deemed unnecessary.

One detail that may or may not be relevant is that I bound each handler to the 'this' object and included function implementations to prevent them from being assigned to the same empty function by the compiler. Additionally, my code utilized a GET method rather than POST. Your mileage may vary.

Your code appears to have one unset handler:

if (window.XDomainRequest) // Check browser support for XDR.
{
    xdr = new XDomainRequest(); // Instantiate a new XDR object.
    if (xrd) {
        xdr.timeout = 3000; // Set timeout to 3 seconds.
        xdr.onload = function () {
            alert("Success");
        };
        xdr.onerror = function () {
            alert("Error");
        };
        xdr.ontimeout = function () {
            alert("Error");
        };
        // This also requires setting
        xdr.onprogress = function() {
            window.console.log('progress');
        };
        xdr.open("post", urlSearch);
        xdr.send();
    }
}
else {
    $.ajax({
        url: urlSearch,
        type: 'POST',
        dataType: 'json',
        timeout: 3000,
        success: function (data) {
            alert("Success");
        },
        error: function () {
            alert("Error");
        }
    });
}

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

An issue with the form.submit function within an if-else statement

Can anyone help me with submitting a form using AJAX within an if-else statement? I have the code below, but it doesn't seem to be working as expected: $.ajax({ type: "POST", url:'<?php echo base_url() ?>signup/orde ...

Choosing the Laravel 6 option for editing via AJAX: A step-by-step guide

I am looking to update a user who resides in a specific state within a country. The country and state fields are dropdown select options, with a relationship established between them and the user. The state field is populated based on the selected country. ...

Tips for updating DataTable data following a database update:

Struggling with this issue: I've created a view containing PrimeFaces components like <p:datatable /> and <p:contextMenu />. The contextMenu has an actionListener attribute that triggers a method in the Managed Bean to update the current ...

When using $.ajaxSetup, the content type is not configured for Get requests

Snippet 1 $.ajax({url:"1.aspx/HelloWorld",type:"GET",dataType:"json",contentType:"application/json"}); Snippet 2 $.ajaxSetup({ contentType: "application/json", dataType: "json" }); $.get( ...

Tips for modifying the href attribute when a user clicks

Is there a way to dynamically change the value of this link <a href="/Countries/388/10">next</a> without having to refresh the page? For example, if a user clicks on the link, it should update to <a href="/Countries/388/20">next</a&g ...

Reverting back to PDF using jQuery

I am currently utilizing jQuery to send JSON data back to the server, which in turn generates a PDF report. However, I am facing an issue where the PDF is not downloading despite specifying the necessary response header and including JavaScript as shown ...

Is there a way to modify the window's location without having to reload it and without resorting to any sne

Initially, I believed that the hash hack was a necessity, but after observing the recent updates from Facebook, my perspective has shifted. The original hash hack (not certain if this is the correct term) involved changing location.hash to save a state in ...

Refreshing a Thymeleaf table dynamically without having to reload the entire page

I am currently using the Thymeleaf attribute to render data, but I am now looking to add a "Search" button without reloading the page. Within the attribute departments, I am rendering a List<Department> from the database. While I understand how to a ...

Leveraging AJAX and jQuery for data storage

Need a solution using AJAX and jQuery to save data from one form in another form while preserving the values. The stored information should be hidden from the front end user, with an option for the user to delete the data if desired. Retrieving the stored ...

Generate various pagination options in CodeIgniter using the identical index

My search results need to be paginated on the same page using codeigniter. The results are divided into two parts: books and news, so I require multiple pagination with the same index http://xxx/xxx/advancedsearch/searchbasic/index/2?search=. I have implem ...

What's the best way to transfer a variable from a PHP file to a jQuery AJAX file so that it can be used as the URL parameter when sending

I am just starting out with javascript, jquery, and ajax. Unfortunately, I've encountered an issue where my code is not working as expected. Below, you can find a detailed description of my code and the problem at hand. If someone could offer some ass ...

Analyzing length of strings by dividing content within div tags using their unique ids

Here's my issue: I'm using AJAX to fetch a price, but the source from where it is fetched doesn't add a zero at the end of the price if it ends in zero. For example, if the price is 0.40 cents, it comes back as 0.4. Now, my objective is to t ...

Using ASHX to Return JSON in ASP.NET

I have implemented autocomplete functionality on my website. The JavaScript part is complete and I am able to retrieve the MembershipUser object of the matching user. Now, I need to format the JSON response as follows: { query:'Li', suggestio ...

Retrieving Dropdown Values based on Selection in Another Dropdown

On my website, there are two dropdown lists available: 1) One containing Book Names 2) The other containing Links to the Books. All data is stored in an XML file structured like this: <?xml version="1.0" encoding="UTF-8"?> <BookDetail> <boo ...

My WordPress loadmore function is not providing any additional posts

Hey everyone, I'm facing a Wordpress issue that I can't seem to resolve. I've checked other posts but haven't found the solution yet. So, I decided to share my code here and seek help. My problem is with trying to load more posts using ...

Can Ember store in Route handle Post requests?

Is there a way to use ember store functionality similar to this.store.findAll('report') for making POST requests with postObj in my route? Also, how should I handle the response received from these requests? Right now, I am sending ajax POST requ ...

Verifying username using an Ajax call

Currently, I am working on developing a signup form using HTML/CSS/JS that involves utilizing an AJAX request to interact with the server. Within my jQuery code, I have implemented a method for validating the form inputs, which also triggers a function (en ...

Refresh PHP variable without having to refresh the entire website

Is there a way to update the variable $online without having to refresh the website? I have attempted the following: data.php <?php include("steam.php"); $data = $online; // get current value of data from somewhere echo $data; // should ...

When utilizing jQuery in HTML, the Marquee will bounce back upon reaching the end

My issue is that when I use a regular marquee, the text simply goes to the end and does not bounce back to the start as soon as it reaches the end of the div. Instead of using a normal marquee, I am looking to achieve this desired effect by utilizing jQue ...

Sending JSON data stored in a JavaScript variable through a jQuery POST request

I am currently attempting to retrieve data from a remote location using a JQuery post method. It works perfectly fine when I directly input the data to be posted, but for some reason, it fails when I store the JSON in a JavaScript variable and pass it in. ...