我需要帮助来写这个没有async: false,
。Rewite ajax请求和返回的值
var imageX;
var groupX;
$.ajax({
type:'GET',
url:'php/myphp.php',
dataType:'json',
async: false,
success: function(response){
imageX = response[0].studentName,
groupX = response[0].subjectId;
alertImageX();
}
});
function alertImageX() {
(function() {
var image = {
'back': { 'url':imageX, 'img':null },
'front': { 'url':'img/bg.jpg', 'img':null }
};
PHP
$query = $db->prepare('SELECT studentName, subjectId FROM grade3 WHERE eligible = ? LIMIT 1');
$array = array('Yes');
$query->execute($array);
$result = $query->fetchAll(PDO::FETCH_ASSOC);
echo json_encode($result);
期望的结果是什么? – Chitowns24
我希望能够获得由AJAX调用返回的数据(即:imageX)。并避免'async:false',因为这是不好的习惯。 – NathaliaZeed
在成功响应数据的地方,我们可以看到PHP代码以及AJAX代码吗? – Chitowns24