$.get() does not work without a filename specified

$.get() does not work without a filename specified

Hi,

I try to load the contents of a user-specified url, like so:

  1. $.get(
  2.         urlValue, function(data) {
  3.                   alert('page content: ' + data);
  4.          });

This works fine for url's that contain a filename, such as http://mysite.com/index.html

It does not work for url's without a filename specified. such as http://mysite.com or http://mysite.com/
When I try that:
- data is empty (not null, just empty)
- the textStatus is "success" and the XMLHttpRequest.readyState is 4 (= complete).
- XMLHttpRequest.status is 0. I don't think that's a valid status value.
- XMLHttpRequest.getAllResponseHeaders() returns null

However, looking at Firebug I get different results for different web sites:
  • http://www.google.com/
    1. Host www.google.com
      User-Agent Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.2) Gecko/20100115 Firefox/3.6
      Accept */*
      Accept-Language en-us,en;q=0.5
      Accept-Encoding gzip,deflate
      Accept-Charset ISO-8859-1,utf-8;q=0.7,*;q=0.7
      Keep-Alive 115
      Connection keep-alive
      Referer http://godspeedelbow.com
      Origin http://godspeedelbow.com
    the response is:
    1. Failed to load source for: http://www.google.com/
    That's not a valid response, I think so hence the status = 0, maybe?



  • http://getfirebug.com/logging
    1. Request header
    2. Host getfirebug.com
      User-Agent Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.2) Gecko/20100115 Firefox/3.6
      Accept */*
      Accept-Language en-us,en;q=0.5
      Accept-Encoding gzip,deflate
      Accept-Charset ISO-8859-1,utf-8;q=0.7,*;q=0.7
      Keep-Alive 115
      Connection keep-alive
      Referer http://godspeedelbow.com
      Origin http://godspeedelbow.com


    1. Response Header
    2. Date Mon, 15 Mar 2010 12:28:17 GMT
      Server Apache
      Content-Location logging.php
      Vary negotiate
      TCN choice
      X-Powered-By PHP/5.2.9
      Cache-Control max-age=1, private, must-revalidate
      Expires Mon, 15 Mar 2010 12:28:18 GMT
      Keep-Alive timeout=5, max=971
      Connection Keep-Alive
      Content-Type text/html; charset=UTF-8
      Content-Encoding gzip
      Transfer-Encoding chunks

The response actually contains the html. So, somehow Firebug has loaded it, but it was not passed to javascript? Also, I notice that there's a location: logging.php value in the Response header.


What could I do to make this work? Do I first need to make a HEAD request to retrieve the location of the file and then request the contents of that file?

Thanks a lot!
Eelke


















    • Topic Participants

    • eelke