0
次のコードに問題がありますが、必要なデータを取得しますが、実行時にコンソールに表示されるdiv #playercontentに追加されません。DivにAJAX応答データを追加
PHP、Slim、HTML、JSONで作業する。それをクリアする。
$(document).ready(function(){ $.ajax({ type: 'GET', dataType: "json", url: "db.php/players", success: showResponse, error: showError }); }); console.debug("error"); function showResponse(responseData){ $("#get1").click(function getPlayers(responseData) { console.log('Image is clicked'); console.log(responseData); $.each(responseData.player, function(index, player){ console.log(' is '); $("#playercontent").append(" </br>Player Position:" +player.PlayerPosition+"</br> Full Name:" +player.PlayerName+ " "+player.PlayerLastName+" </br>Team Name:" +player.TeamName); // $("#playercontent").append("</li>"); console.log('Data should output'); }); }); console.log(responseData); } console.debug("hello"); function showError(){ alert("Sorry, but something went wrong. Fix it!!!!") }
タグでないスパムを行ってください。あなたの質問は、「スリム」でも「PHP」でも関係していません。関数 '$(ドキュメント).ready(関数(){...}' '内部showResponse'を移動してみてください@MarcinOrlowski –
おかげで。私たちは確か要素' playercontent'は、関数の前に存在する 'にshowResponseようにする必要があり'が定義されています。 –
あなたの助けの伴侶のため – alfredo