我正在使用JQuery 什么时候。语法如下所示:
$.when(
// Get the HTML
$.get("/feature/", function(html) {
globalStore.html = html;
}),
// Get the CSS
$.get("/assets/feature.css", function(css) {
globalStore.css = css;
}),
// Get the JS
$.getScript("/assets/feature.js")
).then(function() {
// Add CSS to page
$("<style />").html(globalStore.css).appendTo("head");
// Add HTML to page
$("body").append(globalStore.html);
});我的问题
发布于 2014-09-02 08:06:18
deferred.then( doneCallbacks,failCallbacks )可以接受类似的故障过滤器
$.when(
// Get the HTML
$.get("/feature/", function(html) {
globalStore.html = html;
}),
// Get the CSS
$.get("/assets/feature.css", function(css) {
globalStore.css = css;
}),
// Get the JS
$.getScript("/assets/feature.js")
).then(function() {
// Add CSS to page
$("<style />").html(globalStore.css).appendTo("head");
// Add HTML to page
$("body").append(globalStore.html);
}, function(){
//there is an exception in the request
});要设置超时,可以使用timeout选项。
您可以在全局范围内使用它,比如
jQuery.ajaxSetup({
timeout: 5000
})或者使用$.ajax()代替短版本的$.get()和timeout选项。
发布于 2014-09-02 08:08:05
我认为这是因为调用是异步的。使用时:
$.ajax({
url: "file.php",
type: "POST",
async: false,
success: function(data) {
}
});呼叫是同步的。
https://stackoverflow.com/questions/25618593
复制相似问题