javascript - Printing out HTML via an Ajax-Request that is having errors stops further JS from working -


i made little experiment site. have site, empty. makes ajax-request php file random website being gathered. website being gathered using multiple random words, doing search request them google , select random result. curl follow result , print out contents, , set in ajax-request html. then, next page should gathered.

however, problem is, after website loaded, website has javascript errors (probably because of paths or sth?)

how fix this? code. said, it's experiment, i'm not using prototypes, classes, tests, comments or whatever, plain stupid writing code down

<section id="content"> </section> <script type="text/javascript" src="https://code.jquery.com/jquery-2.2.0.min.js"></script>  <script type="text/javascript">     $(document).ready(function(){         newsite();          function newsite()         {             $.ajax({                 url: 'sites.php',                 datatype: 'html'             }).done(function(data) {                 $('#content').html(data);                 $('#content').scrolltop(300);                  newsite();             });         }     }); </script> 

and site contents , print them out in php file (i'm not showing full code here, because there stuff don't need)

$ch = curl_init();  // set url , other appropriate options curl_setopt($ch, curlopt_returntransfer, true); curl_setopt($ch, curlopt_header, false); curl_setopt($ch, curlopt_useragent, $useragent); curl_setopt($ch, curlopt_followlocation, 1); curl_setopt($ch, curlopt_url, $final);  $content = curl_exec($ch);  echo $content; 

$final url of google result. ideas?

if want load random website, can't insert first page in own document, site has other files load relative path won't work in page (js, images,...).

you can strip js content, sites break without it, , if doesn't still missing parts.

instead of sending content, send url php code , use window.open display target website (and window.close close previous one).

for instance:

var windowref = window.open(url, name); 

usually window opened in new tab. if name not empty, window reuse tab opened same name instead of opening another.


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -