IE8 does not properly execute AJAX call to PHP file

It's strange, it works perfectly fine in Firefox.

This is the JavaScript code I'm using:

star.updateRating=function(v, listid) { 
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null) {
    alert("Looks like AJAX isn't supported by your browser!");
    return;
}  
var randomnbr = randomID(12); 
var cacheid = randomnbr+"_"+listid;              
var url="http://mywebsiteurl.com/includes/functions_rating.php";                 
    url=url+"?action=ratelist";                      
    url=url+"&listid="+listid;                   
    url=url+"&rating="+v;    
    url=url+"&cid="+cacheid;      
// disable the container 
$('starMsg').innerHTML=' - Thanks for rating!';
$('star').setAttribute('onmousemove','');
$('star').setAttribute('onmousedown','');

xmlHttp.open("POST",url,true);
xmlHttp.send(null);   

}

At the beginning of my PHP file, I have: header ("content-type: text/xml");

Despite the JavaScript running completely (I even have an alert(1); at the end), the PHP script fails to update the database when called from Internet Explorer.

Any suggestions on what might be causing this issue?

Answer №1

Have you considered utilizing a tool such as jquery to address the variations in different browsers?

Answer №2

To ensure compatibility with both Internet Explorer and Firefox, use the following code to get the Object correctly:

function GetXmlHttpObject()
{
  if (window.XMLHttpRequest)
  {
    // code for IE7+, Firefox, Chrome, Opera, Safari
    return new XMLHttpRequest();
  }

  if (window.ActiveXObject)
  {
    // code for IE6, IE5
    return new ActiveXObject("Microsoft.XMLHTTP");
  }

  return null;
}

Then, call the function like this:

xmlhttp=GetXmlHttpObject();

It is worth noting that you may actually be retrieving the object correctly, although you have not provided details of your GetXmlHttpObject() function. If you are using xmlhttp.send(null) with the POST method, ensure that you are not sending an empty request to the server. Either include the variables to be sent in .send(), or switch to the GET method and append the variables to the URL.

Answer №3

xmlHttp.open("POST",url,true);
xmlHttp.send(null);

send(null) may be causing the issue at hand.

To rectify this, consider using send('') to send an empty body or simply omit the parameter altogether (send()). The XMLHttpRequest interface does not specify including a null parameter.

Typically, for a POST request, it is customary to send the form-encoded (a=b&x=y) string as the request body instead of including it in the query string.

Given that adding a rating is a state-changing action, it is recommended to use POST rather than GET.

Answer №4

What is the process for initializing your XMLHTTPRequest object? Keep in mind that separate methods are required for IE and Firefox.

Answer №5

Oops, I ran into an issue in my PHP file. Turns out I was using a different user in Internet Explorer compared to Firefox, which is why I didn't notice it right away. Interestingly, there were actually two problems at play here, and one of them was resolved by switching back to using the GET method. (I had switched to POST initially based on advice from other questions regarding IE ajax issues).

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

Discover the key to optimizing your JavaScript development workflow by automating project structures and eliminating the need to start from scratch

I was looking for a way to streamline the process of setting up project structures for my projects so that I could utilize ALE linting and fixing without any hassle. After trying out one method, I'm confident that there must be a more efficient soluti ...

Utilizing React JS with Material-UI Autocomplete allows for seamlessly transferring the selected item from the renderInput to the InputProps of the textfield component

Exploring the functionality of the updated version of Autocomplete, my goal is to ensure that when an element is chosen from the dropdown menu, the input format of the text field will be modified to accommodate adding a chip with the selected text. Is the ...

Displaying results of data from a cross domain request

I have some test code related to WordPress displayed below. jQuery(document).ready(function($) { var link = 'http://000.00.00.00/cgi-bin/test.cgi'; $("#sub").click(function() { $.ajax({ type:'POST', url: link, ...

Encountering a mistake due to the anticipated atom not being found at the specified

In my react application, I am encountering an issue with allowing foreign characters along with English in the input field of a form. I have implemented a regular expression as follows: const alphabetRegex = /^([A-Za-z]+ )+[A-Za-z]+$|^[A-Za-z]*\p{L}/g ...

Performing AJAX requests to dynamically update multiple DIVs

Encountering difficulties with adding additional input fields to a page, each of which contains jquery code for appending more select boxes related to them. The base html setup is as follows: <p id="add_field"> … </p> <div class="show_sub ...

Inquire: How can I transfer a value from one form to another HTML document, and then retrieve and utilize the value in JavaScript?

My goal in Express is quite complex, as I need to retrieve data from the form located in 'inputdata.html' (with a ROUTE of '/inputdata'). This data will then be passed to 'info.html' (with a ROUTE of '/info') Once ...

An error was encountered: An identifier that was not expected was found within the AJAX call back function

I am experiencing an issue while attempting to query an API. An Uncaught SyntaxError: Unexpected identifier is being thrown on the success part of my JQuery Ajax function. $(document).ready(function(){ $('#submitYear').click(function(){ let year ...

Signs that indicate a site is being accessed through an AJAX request

Hey there, I have developed an API for my topsite that I share with my users to display on their webpages. This is the API code: <script type="text/javascript"> var id = 21; $(document).ready(function(){ $.getJSON("http://topsite.com/inde ...

Utilizing Ajax to dynamically update the content of a div element

As a newcomer to Ajax, I am trying to use xmlhttprequest to dynamically change the content of a div by fetching HTML from different URLs. However, my code doesn't seem to be working as expected. Can someone help me identify what I might be doing wrong ...

What could be causing the JSON.stringify() replacer function to fail?

Here is the code snippet I'm working with: http://jsfiddle.net/8tAyu/7/ var data = { "foundation": "Mozilla", "model": "box", "week": 45, "transport": { "week": 3 }, "month": 7 }; console.log(JSON.stringify(data, ...

What is the most efficient method to import multiple MaterialUI components using a shared namespace without requiring the entire library to be imported

In order to prevent name mixing with other libraries, I want my MaterialUI components to be under the same namespace. For example, ensuring that <Box> references <MaterialUI.Box> and not <SomeOtherLibrary.Box>. Although it seems like a si ...

Using single page anchor tags in Next.js to toggle content visibility

The Issue Currently working on a project using Next.js and facing a challenge: needing to hide or replace content based on the selected category without reloading the page or navigating to another route. Furthermore, ensuring that when the page is reloade ...

Performing an Ajax Get Request in Rails 4 without rendering a view

Welcome to a unique question that has been carefully crafted to stand out from the rest. After hours of dedicated research, it seems like the right terms are still eluding me. In the world of Rails 4, my aim is to utilize an ajax request to fetch data fro ...

Leverage the exported data from Highcharts Editor to create a fresh React chart

I am currently working on implementing the following workflow Create a chart using the Highcharts Editor tool Export the JSON object from the Editor that represents the chart Utilize the exported JSON to render a new chart After creating a chart through ...

Guide on sending information using ajax using a button within a form

I've been working on creating a form that utilizes HTML5 validations and integrates Ajax to show the status of mail sending. However, I'm facing an issue where clicking the send button does not initiate the expected action. Form HTML: <div c ...

Inspecting JavaScript for any attachments

Before hitting the submit button, I need to verify if a file has been uploaded and display a warning message prompting the user to attach a file if it hasn't been done yet. I am looking for guidance on how to achieve this using JavaScript, Prototype, ...

Verify if a request attribute has been established using jQuery

How can I determine if an attribute is present in a request object? I have specific error scenarios where an error message needs to be sent to the client side: Here is the servlet code snippet: request.setAttribute("error", "The following term was not fo ...

What could be causing the error when using Context.Response.Write()?

I'm currently learning ASP.Net development and running into an issue while trying to send data from a web service to a web form. I have been utilizing the JSON method, but encountering an error in the following line of code which is resulting in a com ...

Retrieve specific information from checkboxes within a form

I'm working on a form that includes multiple checkboxes populated with data from a JSON file using ng-repeat. After submitting the form, I need to retrieve the data from the checked checkboxes. How can I accomplish this in my controller after the form ...

Is there a way to retrieve information from all pages of a table on a webpage using Chrome?

On a webpage, I have a table containing 100 rows that are displayed 20 at a time. By clicking "next page," I can view the following set of 20 rows and the table view is updated accordingly. I am able to access the data for each batch of 20 rows using dev ...