tags:

views:

130

answers:

2

hi is there a wait to load a full url.?

url= 'http://www.example.com/whatever.php'
$('#selector').load(url);  // this way returns null (empty result)

instead of :

url = 'whatever.php'
$('#selector').load(url); // works fine

Some may think whats the difference i want to use this because im using multiple directories. so i could be on a page like...

example.com/dir/

but the dir folder will not have the whatever.php so anyone has a fix for this that i should always use the full url? thank you.

A: 
No, there isn't. If `http://www.example.com/` takes longer to load than `http://example.com/` then it is probably because you have the DNS record for `example.com` cached but not the record for `www.example.com`.

Corrected after having realized a typo changed the meaning of the question.:

This is a case of having a mismatch between the host name the page is loaded from and the host name the Ajaxed resource is requested from. i.e. The Same Origin Policy.

Pick a host name to be canonical, use that one in your requests, and redirect (with a 301 status code) from the other so that people don't go to the wrong one by mistake.

David Dorward
`http://www.example.com` does not return anything at all. where as `http://example.com` returns what ever its in it. ... does it have disadvantages by using it without the www ?
Val
Ooooh. "Wait" was a typo for "Way"
David Dorward
+2  A: 

You could always use relative paths

putting / before the path will tell the browser to go the root of the page. For your example you could call /whatever.php.

You can also move up one directory at a time. Lets say you are in a page at http://www.example.com/dir/foo/bar.php and want to access something in the dir folder, you could specify ../inTheDir.php to move up one directory or ../../inTheRoot.php to move up two.

This should work for you, but based on your comment it sounds like you have a problem somewhere else since your www. page doesn't seem to respond correctly.

Gordon Tucker
thats a clever trick... however this could be a silly setting on the www so ... thank you
Val