The HTTP request seems to be malfunctioning

When attempting to establish a connection and retrieve data from a PHP file using an AJAX request, it's important to note that the AJAX JS is located on a different website. Here is the script being used:


var quer;
try
{
  quer = new XMLHttpRequest(); // This line gets called when running in Safari.
}
catch (e)
{
  try
  {
    quer = new ActiveXObject("Msxml2.XMLHttp");
  }
  catch (e)
  {
    try
    {
      quer = new ActiveXObject("Microsoft.XMLHttp");
    }
    catch (e)
    {
      return false;
    }
  }
}

quer.onreadystatechange = function(){
  if (quer.readyState == 4) // Data retrieval successful.
  {
    var resp = quer.responseText;
    alert(resp);
  }
}

quer.open("POST", "(URL hidden for security reasons)", true);
quer.send(null); 

The 'resp' variable always remains empty. Can someone provide assistance with this issue?

Answer №1

The JavaScript used for AJAX is hosted on a separate website from the PHP.

This seems to be causing the issue. Cross-origin requests via XMLHttp are not allowed.

For more information, you can explore the concept of the same origin policy.

Answer №2

It is not possible to send AJAX requests to scripts located on different domains as it goes against the same origin policy.

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 arises with React hooks: useMemo and useEffect display a Missing dependency error when attempting to invoke a function

triggerData function is being utilized in multiple functions. However, if I place the function inside the useEffect to prevent missing dependencies, then I am unable to call the triggerData outside of the useEffect i.e., in buildData. How can I resolve the ...

JQuery: Issues with attaching .on handlers to dynamically added elements

I'm currently developing a comment system. Upon loading the page, users will see a box to create a new comment, along with existing comments that have reply buttons. Clicking on a reply button will duplicate and add the comment text box like this: $( ...

Experiencing AJAX response error in the Laravel Blade Template

I'm encountering an issue with my AJAX response. When I click the 'view' button in the 'All Patient' table, I am trying to view specific patient details using an AJAX request. However, I keep getting an error in the response, sim ...

Running a node.js project on the client side without using npm for deployment

Looking for a solution to efficiently deploy my nodejs project with frequent updates. The site does not have npm available, so I have to package the node_modules every time, which results in a large file size (80MB) that takes a long time to send via ftp t ...

Having trouble configuring the Access-Control-Allow-Origin header to function as originally intended

Despite numerous inquiries on this topic, I'm still unable to resolve my issue. I've been attempting to make a game work with HTML5 in Chrome. You can find the link here. The game is coded using libgdx and I'm sending json data from my app ...

What is the procedure for updating or adding data to a JSON file with angularJS?

After successfully creating a local JSON file and retrieving data from it using app.controller('appCtrl', function($scope, $http){ $http.get('employees.json').success(function(data){ $scope.employees=angular.fromJson(data.employee ...

activated by selecting a radio button, with a bootstrap dropdown menu

I'm having trouble triggering the dropdown in Bootstrap by clicking on a radio button. It seems like a simple task, but I've been struggling with it all day. According to Bootstrap documentation, you can activate the dropdown using a hyperlink o ...

Utilize AJAX to send a file within an HTTP request

In my attempt to send a form using an Ajax request, I encountered a challenge with uploading files. Here is a snippet of my form: <form> {{csrf_field()}} <div class="form-group"> <label for="company-name">Co ...

JavaScript stylesheet library

What is the top choice for an open-source JavaScript CSS framework to use? ...

JQuery's .ajax function often triggers the success callback before the page it is calling

Below is the code I am currently working with: <script type="text/javascript"> $(function(){ $("#AddMaps").submit(function(){ var $form = $('#AddMaps'); $.ajax({ type: 'POST&a ...

Regex: Enabling commas in the name of an Excel file

My JavaScript code is set up to extract data from an excel file. As a first step, I define a regular expression and assign it to a variable named regex var regex = /^([a-zA-Z0-9\s_!()\\.\-:])+(.xls|.xlsx)$/; Following this, there is s ...

Is there a way to dynamically assign column names during the import process?

In my current scenario, I am importing data from various sources into my JSON backend. The mapping file will resemble the sample below. The question is how can I efficiently utilize this mapping during data import into my backend. The idea is to provide t ...

How to showcase base64 encoded images in pug (jade) with node.js

Can anyone help with decoding this mysterious data and displaying the image? I'm using pug as my template engine. Below is the questionable data that needs to be shown as an image: /9j/4AAQSkZJRgABAQEAYABgAAD/4QBaRXhpZgAATU0AKgAAAAgABQ ...and so f ...

Struggling to incorporate infinite scroll feature into JSON script that is already functioning smoothly

After developing a phonegap application, I created a page called photos.html to fetch photos from my server using JSON. However, despite successfully retrieving all the photos stored in my MySQL database on the server with JSON, I struggled to integrate In ...

How can we best understand the concept of custom directives using the link method?

As a beginner in AngularJS, I am looking to implement an autocomplete feature for text input. My JSON data is stored in JavaScript and I need help simplifying the process. Can you provide me with a straightforward solution? The specific requirement is to ...

Execute the function within setInterval only one time

I have a setInterval function that calculates the time difference between a specified date and the current time. Once this difference is less than an hour, I want to execute some code only once. const countdownDate = new Date('March 15, 2021 11:30:00& ...

What is the best approach for creating a test case for a bootstrap-vue modal component

Exploring ways to effectively test the bootstrap vue modal display function. On the project page, the modal toggles its visibility using the toggleModal method triggered by a button click. The modal's display style is switched between 'none' ...

A step-by-step guide on duplicating the functionality of the jQuery

Issue at Hand: I'm attempting to recreate the functionality of jQuery's ajax method as I find myself utilizing XMLHttpRequest multiple times within a script. However, I am hesitant to include jQuery as a dependency since I only require a few meth ...

Passing Selected Table Row Model Data to Backend in Angular 7

My goal is to send the selected data in a table row, which I select through a checkbox, to the server. However, I'm unsure about how to handle this via a service call. While I have the basic structure in place, I need assistance with sending the items ...

Obtaining the data stored in objects within a parse database

I'm currently facing an issue where I am trying to retrieve the name of the creator from the session object, which is a pointer. For testing purposes, I have been attempting to access this information but it keeps showing up as undefined. Any suggesti ...