javascript - When making an ajax call I receive "TypeError: e is undefined" -
i trying display contents of website using file_get_contents in php script , ajax on front-end. can display whole page fine if try display amount of images on page, receive "typeerror: e undefined" error. here php:
<?php $url= 'https://twitter.com/twitter'; if($url!="") echo file_get_contents($url); ?>
here jquery:
$.ajax({ url : "twitter.php", datatype: "html", success : function (data) { console.log("loaded"); //$(data).appendto('#images'); $.each(data.items, function(i,item) { $("<img />").attr("src", item.media.m).appendto('#images'); if (i == 5) return false; }); } });
data
html string, iterate on (like dom tree) using jq, you'll have call jq constructor (or init
method). did when tried append current dom:
$(data).appendto('#images'); // \==>$() function call, returns jq instance // when passing markup string, jq parse
the loop, therefore, should like:
$.each($(data), function(){});
and please, try adding in couple of console.log
statements, lot when debugging.