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