views:

160

answers:

1

The code segment is from a page called "sites-catchup.html". There is a simple server side page called "max-change-num-ajax.html" which returns a single number (without any html).

If the page is requested by calling http://tiddy:8080/rsm/sites-catchup.html then it all works.

However if I call http://localhost:8080/rsm/sites-catchup.html the page renders as normal but the ajax bit always fails. Tiddy and localhost have different ip addresses but point to the same machine. If I switch them around so that "sites-catchup.html" loads from localhost, but I request the page from tiddy, then it doesn't work either.

If the load is changed to localhost and I request localhost then it works.

Looking in Firebug, when the host names are the same the load performs a GET request which returns the correct value, but if the host names are different then the load performs an OPTIONS command which always returns nothing.

The ultimate purpose of this will be in a table where each row will have a status pulled in from a different machine, so it will never match the host from which you are requesting the page.

Can't seem to find any reason why this is happening or how to fix it. Can anyone help?

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3c.org/TR/1999/REC-html401-19991224/loose.dtd"&gt;
<html xmlns="http://www.w3.org/1999/xhtml"&gt;

<HEAD>
<link type="text/css" href="js/jquery/themes/base/ui.all.css" rel="stylesheet" />
<script type="text/javascript" src="js/jquery/jquery-1.3.2.js"></script>
<script type="text/javascript" src="js/jquery/jquery-ui-1.7.2.custom.js"></script>
<!--[if gte IE 5.5]>
<SCRIPT language="JavaScript" src="js/jquery.ienav.js" type="text/javascript"></SCRIPT>
<![endif]-->
</HEAD>

<div id="rsmmax1">Fetching1...</div>

<script type="text/JavaScript">
$(document).ready(function() {
   $("#rsmmax1").load("http://tiddy:8080/rsm/max-change-num-ajax.html");
});
</script> 


</BODY>
</HTML>
+2  A: 

This is by design. For security reasons you cannot perform cross domain AJAX requests. You could use JSONP though. Another option is to use a proxy.

Darin Dimitrov