在我的文件之一,我拨打电话如下:如何确保放大请求在返回值之前完成?
var jobsString = getDropdownJobs();
它调用此函数:
function getDropdownJobs() {
var jobsString = amplify.store("JobsList");
if (typeof jobsString === 'undefined') {
// Amplify sends a request for getJobs, if it exists in cache, it will return that value.
// If it does not exist in cache, it will make the AJAX request.
amplify.request("getJobs", function (data) {
// Leave a blank option for the default of no selection.
var jobsString = '<option value=""></option>';
// Append each of the options to the jobsString.
$.each(data.jobs, function() {
jobsString += "<option " + "value=" + this.JobNo_ + ">" + this.JobNo_ + " : " + this.Description + this.Description2 + "</option>";
});
// Store the jobsString to be used later.
amplify.store("JobsList", jobsString);
});
}
return jobsString;
}
凡"GetJobs"
[增强的定义是:
amplify.request.define("getJobs", "ajax", {
url: "../api/Job/Jobs",
dataType: "json",
type: "GET",
cache: "persist"
});
每当它返回,它是未定义的。我在AJAX定义中加入了“async:false”,它没有改变任何东西。
如何在返回之前确认该值是否存在?
看看['$ .Deferred'(http://api.jquery.com/category/deferred-object/)。 – jbabey