I just started messing around with AJAX in an attempt to validate a form with a database before a user can submit something but I have struck a wall with the URL portion of the Open function. When I use the full URL such as http://www.mywebsite.com/folder/file.php it doesn’t work, but when I just use file.php, as in the relative path, it works fine. Any ideas what causes this and more generally what are the rules for the URL portion of Open. Thanks in advance for the help. I’m always amazed at how quickly you reply to my questions.
xmlhttp.open("GET","myFile.php",true); GOOD
xmlhttp.open("GET","http://www.mywebsite.com/folder/myFile.php",true); BAD?
XMLHttpRequests must obey the same origin policy. The requests to a certain domain must come from the same domain. The XMLHttpRequest object enforces that by treating the URL to the
open()method as relative to the base URL stored on the XMLHttpRequest object which is derived from the main Window object using whichever URL the browser is currently at.See the W3C specs for XMLHttpRequest
open()method here