image - Jquery two .get() functions working differently -
the first .get()
function works in browsers , second 1 works every time in firefox, every second time in chrome , not @ in ie.
the code wrapped in $(document).ready
function, should not problem page loading.
the first .get()
function gets recent news rss feed , posts them in <ul>
. second .get()
function gets same things different rss feed , posts them in similar way, difference gets image sources , i'm drawing these images <canvas>
elements in last part of code.
even without drawing images canvas elements, , without getting image sources, second .get() function not work every time in chrome , never in ie. first 1 works every time in browsers.
i using similar piece of code draw other images canvas elements, , works everywhere , everytime.
//the first, working .get() function: $.get("rss-url", function (data) { var $xml = $(data); var $i = 0; $xml.find("item").each(function () { var $this = $(this), item = { title: $this.find("title").text(), link: $this.find("guid").text(), pubdate: $this.find("pubdate").text(), } //do item here... if ($i < 10) { var pv = new date(item.pubdate).tolocalestring(); $("#uutiset_latest > ul").append("<li><a href=" + item.link + ">" + item.title + "</a><br>" + pv + "</li>"); } $i++; }); }); //second, not working .get() function: $(function () { var img0, img1, img2; $.get("rss-url", function (data) { var $xml = $(data); var $i = 0; $xml.find("item").each(function () { var $this = $(this), item = { title: $this.find("title").text(), link: $this.find("guid").text(), pubdate: $this.find("pubdate").text(), pic: $this.find("description").html() } if ($i < 3) { var pv = new date(item.pubdate).tolocalestring(); var parsed = $('<div/>').html(item.pic); var picsrc = parsed.find("img").attr("src"); $("#right_column_feed > ul").append("<li><a href=" + item.link + ">" + item.title + "</a><div id='tsemppi_div" + $i.tostring() + "'><canvas id='tsemppi_canvas" + $i.tostring() + "' width='150' height='100' class='tsemppi_canvas'></canvas></div>" + pv + "</li>"); } switch ($i) { case 0: img0 = picsrc; break; case 1: img1 = picsrc; break; case 2: img2 = picsrc; break; } $i++; }); drawimages2(); }); //the function draw images <canvas> elements: function drawimages2() { var imgwidth = 150; var imgheight = 100; var $z = 0; $(".tsemppi_canvas").each(function () { var ctx = document.getelementbyid("tsemppi_canvas" + $z.tostring()).getcontext("2d"); var canvimage = new image(); canvimage.onload = function () { ctx.drawimage(canvimage, 0, 0, imgwidth, imgheight); } switch ($z) { case 0: canvimage.src = (img0); break; case 1: canvimage.src = (img1); break; case 2: canvimage.src = (img2); break; } $z++; }); }; });
all these function in same .js file, images, webpage , rss feeds on same server .js file.
ok figured out, line:
pic: $this.find("description").html()
i changed text, not html , works in every browser:
pic: $this.find("description").text()
Comments
Post a Comment