|
||||||
| AJAX Web based language that allows asynchronous loading of pages that does not interfere with normal page loading. |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
|
|||
|
I have written a script which is suposed to load the google site with ajax and then write it to the html, so that the google page will load (but with my adress!). This is the code:
Code:
<html>
<head>
<title>Fetch URL</title>
<script type="text/javascript">
function FetchURL() {
var xmlHttp;
try { // Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e) { // Internet Explorer
try {
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e) {
try {
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e) {
alert("Your browser does not support AJAX!\nTo bad.");
document.write("FetchURL won't work.");
}
}
}
xmlHttp.onreadystatechange=function() {
if(xmlHttp.readyState==4) {
if (xmlHttp.responseText.length)
{
alert("given URL has a length of " + xmlHttp.responseText.length);
alert(xmlHttp.responseText);
document.write(xmlHttp.responseText);
}
else {
alert("given URL is empty.");
}
}
}
var URL = "www.google.com";
xmlHttp.open("GET", URL, true);
xmlHttp.send(null);
} //FetchURL()
</script>
<head>
<body onload="FetchURL();">
</body>
</html>
I saw I got the following error message from IE6: The requested URL /www.google.com was not found on this server. Not strange, I don't have google at my server! But I thought the intention with the XMLHttpRequest object was that one can do a request which is not from the server but from the clients computer (to any server and url)? |
| Sponsored Links |
|
|
|
|||||
|
Just a guess, but do you need the http:// to tell it to not look on your server?
So you would change: Code:
var URL = "www.google.com"; Code:
var URL = "http://www.google.com";
__________________
My fun, friendly online games website: Cygnet Games My Squidoo page on Cygnet Games. |
|
|||
|
Quote:
I think for security purposes it is stopped. AJAX works on the same domain only ( or at least when I tried to use xmlHttpRequest on other domain it failed with a security reason ). Using it with other domains allows scripting between different domains which is considered security hole. Again - not 100% sure about that, but I think it is so! scripting between different domains is supposed be forbidden even when using pop-up, frames and iframes. read this one, might be helpful: Cross-Domain Proxy - Ajax Patterns |
|
|||||
|
Very interesting. This is probably why some sites are producing publicly available APIs for people to use.
TriKri: It might be worth looking at google's APIs to see if what you want to do is possible using them.
__________________
My fun, friendly online games website: Cygnet Games My Squidoo page on Cygnet Games. |
|
|||||
|
oubless is correct. Most browsers do not allow you to access different domains using XHR for security purposes. Even if you could, I'm fairly certain that the folks at Google wouldn't be very happy about what you're trying to do. If you are interested in having a Google search on your website check this link out.
Also, you should consider using prototype.js which I personally highly recommend or another JavaScript library. Prototype and many other libraries provide a much more programmer friendly interface for crating AJAX requests...its much easier and cleaner than using XHR yourself. Happy Coding. -Fahlyn
__________________
Visit My Google Group Here: Web Development Innovation |
| Sponsored Links |
|
|
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Considering Ajax, Part 1: Cut through the hype | Ronin | JavaScript and CSS | 0 | 12-13-2006 02:36 PM |
| Myth-Busting AJAX (In)security | Jordan | AJAX | 1 | 12-03-2006 01:21 PM |
| AJAX Evolved | Jordan | JavaScript and CSS | 0 | 09-09-2006 01:12 PM |
| More AJAX Resources | NeedHelp | JavaScript and CSS | 2 | 07-13-2006 12:57 PM |
| Anybody use Ajax? | Dan | JavaScript and CSS | 9 | 07-05-2006 03:25 PM |