1
我有這個代碼與ajax調用。jQuery ajax調用同步vs異步?
var value = 0;
$.ajax({
url: 'http://localhost:3000',
dataType: "json",
type: 'POST',
data: formdata,
success: function(data, textStatus, jqXHR) {
value = data.data;
console.log("Inside: " + value);
},
error: function(jqXHR, textStatus, errorThrown) {
console.log("Error received");
}
});
console.log("Outside: " + value);
執行,給我
Outside: 0
Inside: 100
反正讓它順序運行?
只需在'Inside「事件之後將'console.log(」Outside:「+ value)'代碼放在'success'回調中? – Bergi