开发者

jquery ajax load (full URL)

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 di开发者_如何学Pythonr folder will not have the whatever.php so anyone has a fix for this that i should always use the full url? thank you.


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜