jquery - Error loading src = ' ' when you click (ajax) -
i have need return json. failure when click link item clicked loads video. did requests using jquery, error page reloads. needs ajax, possible?
jquery:
var main = function () { var url = "http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20xml%20where%20url%3d'http%3a%2f%2frss.cnn.com%2fservices%2fpodcasting%2fac360%2frss.xml'%20and%20itempath%3d%22%2f%2fchannel%22&format=json&diagnostics=true&callback=?"; $.ajax({ type: 'get', url: url, async: false, jsonpcallback: 'jsoncallback', contenttype: "application/json", datatype: 'jsonp', success: function (json) { // titulos var titles = json.query.results.channel.item.map(function (item) { return item.title; }); // urls var urls = json.query.results.channel.item.map(function (item) { return item.origlink; }); $(".container-list-podcast ul").append('<li>' + titles.join('</li><li>')); $(".container-list-podcast ul li").each(function (key, value) { var text = $(this).text(); $(this).html('<a class="link-podcast" href="' + urls[key] + '">' + text + '</a>'); }); }, error: function (e) { console.log(e.message); } }); }(jquery); /// problem... $(document).ready(function () { var request = $(".link-podcast").attr("href"); $('.link-podcast').click(function () { $('.video').attr('src', 'request'); }); });
the issue setting src
of image string 'request'
$('.video').attr('src', 'request');
you need perform ajax within callback of click
handler e.g.:
$(document).ready(function () { var request = $(".link-podcast").attr("href");
$('.link-podcast').click(function () { // pseudocode ajax ({ success: function (result) { $('.video').attr('src', result); // or result.url etc } }) }); });
Comments
Post a Comment