Lost Password?

Go Back   CodeCall Programming Forum > Web Development Forum > AJAX

AJAX Web based language that allows asynchronous loading of pages that does not interfere with normal page loading.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 07-21-2007, 05:45 AM
TriKri TriKri is offline
Newbie
 
Join Date: Jul 2007
Posts: 2
Rep Power: 0
TriKri is on a distinguished road
Default Fetching google.com with AJAX?

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>
But it doesn't work!

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)?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #2 (permalink)  
Old 08-12-2007, 06:20 AM
CygnetGames's Avatar   
CygnetGames CygnetGames is offline
Programmer
 
Join Date: May 2007
Location: York, England
Posts: 113
Rep Power: 5
CygnetGames is on a distinguished road
Default

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";
to:
Code:
var URL = "http://www.google.com";
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 09-03-2007, 09:34 AM
oubless oubless is offline
Newbie
 
Join Date: May 2007
Posts: 21
Rep Power: 5
oubless is on a distinguished road
Default

Quote:
Originally Posted by CygnetGames View Post
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";
to:
Code:
var URL = "http://www.google.com";
not sure this will work either ...
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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 09-06-2007, 09:25 AM
CygnetGames's Avatar   
CygnetGames CygnetGames is offline
Programmer
 
Join Date: May 2007
Location: York, England
Posts: 113
Rep Power: 5
CygnetGames is on a distinguished road
Default

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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 11-03-2007, 10:37 PM
fahlyn's Avatar   
fahlyn fahlyn is offline
Learning Programmer
 
Join Date: Nov 2007
Age: 24
Posts: 35
Rep Power: 3
fahlyn is on a distinguished road
Send a message via ICQ to fahlyn Send a message via AIM to fahlyn Send a message via MSN to fahlyn Send a message via Yahoo to fahlyn
Default

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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

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


All times are GMT -5. The time now is 09:10 PM.

Contest Stats

dargueta ........ 93.00000
John ........ 87.50000
Xav ........ 50.00000
MeTh0Dz ........ 20.00000
gaylo565 ........ 18.00000
Johnnyboy ........ 3.00000

Contest Rules

Ads