0
我想在另一個jquery函數裏面使用jquery設置var,但是它沒有設置var。我嘗試了幾種方法。這裏是最後的從jquery函數裏面設置var jquery函數不運行
jQuery(function($){
var pipeURL = "xxxxxxxxx.json";
var feedSuccess = function(data, status){
//var html = "<ul>";
var html = "";
var desc = "";
var description = "";
var start = "";
$.each(data.value.items, function(i,item){
//desc = item.description.replace("<br />"," ");
desc = item.description;
desc = desc.substring(0,600);
desc += "...";
descr = desc.replace(/(?:(?!UTC).)*/i,"");
$.getJSON(
"https://graph.facebook.com/"+item.eid+"/?fields=start_time&access_token=xxxxxxxxxxxxxxxxxx",
function(data){
start = data.start_time;
});
html += "<h3 class='pipes'><a class='pipes' href="+item.link+" target='_blank'>" + item.title +"</a></h3>"+"<p class='pipes'>"+start+"</p>"+
"<br/><a class='pipes' href="+item.link+" target='_blank'><img class='pipes' src='"+item['media:thumbnail'].url+"' ></a><br/>" ;
});
//html += "</ul>";
//Add the feed to the page
$("#insertFeed").empty().append(html);
};
$.ajax({
dataType: "json",
url: pipeURL,
success: feedSuccess,
timeout: 6000
});
});
定義var'html'的行與功能數據「var start」中的信息無法正常運行。它顯示標題正常,圖像正常,但「開始」顯示空白。
,如果您正確格式的代碼,你很可能會自己解決這個問題,或者至少是更容易讓別人幫你。 – 2015-04-06 02:48:56
將'html'代碼UP移動到定義了'start'的函數中,在它定義之後 – 2015-04-06 02:49:41
http://blog.slaks.net/2015-01-04/async-method-patterns/ – SLaks 2015-04-06 02:51:40