Flynn
Flynn

Reputation: 11

HTTPrequest is not working

I'm trying to use an ajax request to connect, and gather data from, a PHP file. THe AJAX JS is on a different website than the PHP, just an FYI.

Here is the JS:

var quer;
 try
 {
  quer = new XMLHttpRequest();//I'm running in safari, so this gets called.
 } 
 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)//Good to go.
  {
   var resp = quer.responseText;
   alert(resp);
  }
 }
 quer.open("POST", "(blanked URL for security reasons)", true);
 quer.send(null); 

Resp is always, and I mean ALWAYS blank. Can anyone offer any help?

Upvotes: 1

Views: 664

Answers (2)

CrayonViolent
CrayonViolent

Reputation: 32532

You cannot make AJAX requests to scripts that reside on other domains. It is a violation of the same origin policy.

Upvotes: 0

Guffa
Guffa

Reputation: 700192

THe AJAX JS is on a different website than the PHP

There is your problem. You can't do an XMLHttp request from a different domain.

You can read more about the same origin policy.

Upvotes: 1

Related Questions