0
遇到以下代碼時遇到問題,它會獲取我想要的數據,但它不會附加到div #playercontent,而會在運行時出現在控制檯中。將AJAX響應數據添加到Div
使用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!!!!") }
請標籤沒有垃圾郵件。你的問題既不與'Slim'也不與'PHP'相關。 –
感謝您的幫助mate @MarcinOrlowski –
嘗試在'$(document).ready(function(){...}'內移動函數'showResponse'。我們需要確保'playercontent'元素存在於函數showResponse '被定義。 – alfredo