开发者

jQuery.ajax access file outside root directory

开发者_JAVA百科Can i use jQuery.ajax({ url:"url"});to access a file outside root directory?


You can use AJAX to access any file on your domain that would be available by typing it into a web browser's address bar. You cannot access files that are outside /public_html any more than you would by pointing your web browser at them.

Indeed, you wouldn't want to -- any user can simulate an AJAX request, and would then be able to see any of your server's configuration files!

You will need to write a server-side script that will proxy your request, or just move the relevant file into the public_html directory or a subdirectory thereof.


You can use the ajax method to access anything visible to the web. However, if you do this then you're likely to fall foul of the Same Origin Policy. This usually prevents you from doing an AJAX request outside of your own domain.

However, you can set your requests to be treated as JSONP. This is how you can use JavaScript to get Twitter results, etc.

Go to the ajax documentation and scroll down to see the discussion on JSONP.


If the url is of the same domain then you can issue an AJAX request to that.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜