Is there any way to load a HTML file using plain Javascript and AJAX from an external page and show it ?
Asked
Active
Viewed 764 times
0
-
Then you need to learn Ajax... – Bhojendra Rauniyar Sep 02 '14 at 11:32
-
check this http://stackoverflow.com/questions/17636528/how-do-i-load-an-html-page-in-a-div-using-javascript – Sohil Desai Sep 02 '14 at 11:33
-
@C-linkNepal Good, I updated my question including AJAX since I know how to use AJAX but not this specifically – EnexoOnoma Sep 02 '14 at 11:34
1 Answers
0
It's not so simple if it comes to external page because of the crossdomain issues, the simplest solution would be to use some backend i.e. Python, Ruby, PHP with Javascript (ajax)
- Javascript calls i.e. PHP file on same server
- PHP
curl
the external page and returns content - Javascript after retrieving content process it and then adds to DOM i.e. with
.innerHTML
http://www.w3schools.com/jsref/prop_html_innerhtml.asp

maurycy
- 8,455
- 1
- 27
- 44
-
-
You can find php->curl documentation here http://php.net/manual/en/book.curl.php with some working example, from JS point of view it will be just a standard Ajax call and `.innerHTML` after data receiving – maurycy Sep 02 '14 at 11:47
-
-
Well first of all file_get_contents is just a simple screwdriver when curl is a powerful tool, although it might be overkill if i think about it second time. And secondly I've met hostings service that were setting `allow_url_fopen` to false/0 for so called 'security' reasons so file_get_contents don't work there, but OP can try it, no harm in doing so ;) also cURL seems to be faster as well in most cases – maurycy Sep 02 '14 at 11:57