在 $.ajax() 之外使用时,如何让 imageX 显示它的值(value)?
var imageX;
$.ajax({
type: 'GET',
url: 'php/my1.php',
dataType: 'json',
async: 'false',
success: function(response){
imageX = response[0].studentName,
groupX = response[0].subjectId;
}
});
alert(imageX);
改变
异步: 'false',
到
异步:错误,
'false' 是由 Jquery(JS) 转换为 true 的字符串。
Jquery Ajax 文档说异步接受 bool 值。
async (default: true): Type: Boolean By
default, all requests are sent asynchronously (i.e. this is set to
true by default). If you need synchronous requests, set this option to
false.
https://api.jquery.com/jQuery.ajax/
异步:错误
将导致 jQuery.ajax() 调用阻塞,直到它返回。
而不是这个:
function your ajax_calling_function
call your ajax
callback with results