私は2つの方法を持っています。2 番目のものは最初のものを呼び出します。アラート関数を最初の関数に入れると、戻り値が表示されます。しかし、2 番目の関数では値が未定義と見なされます。なぜ2.値を処理できないのか理解できませんでしたか?
function getTweetReply(id_str) {
$.getJSON("get_tweet_reply.php", {id_str: id_str}, function(json) {
tweet_relpy = '<blockquote>'+json.results[0].text+'</blockquote>';
alert(tweet_relpy); // --> I can see the result
return tweet_relpy;
});
}
$(document).on("click", ".tweet",function(){
var id_str = $(this).attr("id");
$.getJSON("get_tweet_details.php", {id_str: id_str}, function(json) {
tweet = '<img src="'+json.results[0].profile_image_url+'"><br>\
' + json.results[0].from_user + '<br>\
' + json.results[0].from_user_name + '<br>\
' + getTweetReply(json.results[0].id_str) + '</b><br>'; // --> undefined
$("#float").html('<div id="replybox">'+ tweet +'</div>');
});
});