1

I am unable to write external HTML using JavaScript.

Can anyone help me using php and JavaScript like this way.

<div id="include"></div>

in this i want to put HTML from another server.

<script type="text/javascript">
var a = "SRC='http://demoserver.com/read_files.php?f1=headermenu.html";
document.write ("<script type='text/javascript' "+a+"'>");
document.write("</scr"+"ipt>");

here is my php code on my server

<?php
    $url = 'http://demoserver.com/headermenu.html';
    $htm = file_get_contents($url);
    echo $htm;
?>

and html code is

<ul class="menu-link">
<li><a href="">Menu1</a></li>
<li><a href="">Menu2</a></li>
<li><a href="">Menu3</a></li>
<li><a href="">Menu4</a></li>
</ul>
  • You need to use AJAX. http://api.jquery.com/jquery.ajax/ Here are some other options, http://blog.mgechev.com/2011/07/21/ajax-jquery-beginners/. – chris85 Mar 08 '15 at 14:40
  • when i used Ajax this show Cross-Origin Request Blocked: – user3185602 Mar 08 '15 at 14:43
  • Why not use `` in your HTML file and rename it to PHP? – Mouser Mar 08 '15 at 14:46
  • 1
    I thought your PHP was making the request to the remote server? Well if you want to do it client side you'll need JSONP i believe. http://stackoverflow.com/questions/2067472/what-is-jsonp-all-about – chris85 Mar 08 '15 at 14:48
  • Hi mouser there is no option for php there is only html – user3185602 Mar 08 '15 at 14:51
  • @chris85 can you please share live example for it .i am unable to do this – user3185602 Mar 08 '15 at 16:04
  • For JSONP or how this would be done with PHP and ajax? I don't use JSONP thats a suggested way I know other developers have gone when trying to achieve this client side, try searching. Im not sure what you mean by "there is no option for php there is only html". You have PHP in your question and tagged. – chris85 Mar 09 '15 at 03:05

0 Answers0