Hello Javascript master, Can I ask some question? I have 2 website, 1 website is almost run out of bandwidth, I don't want to upgrade and I have an idea to share bandwidth between my website. My question is, how can I -- print source from a file located at some website -- and show it at client browser side using javascript. I know how to do this using PHP, but PHP is server side script, and thats why PHP cannot save my bandwidth using this method. I need to use javascript, so visitor can directly load the content from my other website. this is the code if i using php <? $a = file_get_contents("http://mywebsite/code_file"); echo $a; ?> PHP: How to do it using javascript? This is my idea using javascript <html> large_html_data_no_1 <script type="text/javascript"> <!-- document.write(http://mywebsite/code_file); // --> </script> </html> Code (markup): inside hxxp://mywebsite/code_file is "large_html_data_no_2" the result is : <html> large_html_data_no_1 large_html_data_no_2 </html> when my visitor load my website. How can I do this using javascript? Thank You.
Why don't you use iframes? I know they are bad for spiders but accessibility-in-general but is the content such that it can do without it?
Well its ok if this will not solve the bandwidth problem, please anyone know how to do it? or point to me where to read? Javascript is new to me, i like to learn it by making code with it. Thanks.
Shorter question. How do I read a file (located at remote URL) into a JavaScript variable and print it? I know hot to print it, using document.write, but i don't know how to read a file (located at remote URL) and insert it to JavaScript variable. Have any idea? Thank You
you can't, your needing XMLHttpRequest, but XMLHttprequest only works on the same site not for remote sites. you'll need to use an IFrame as suggested OR in php header('Location: http://remoteUrl'); which will redirect them. more sensible approaches would be to change your hosting/isp/package