簡體   English   中英

Ajax函數和異步:false

[英]ajax function and async: false

這里有一個奇怪的情況.....

我有一個無法編輯的函數。(由於某種原因,我需要使用它而不是創建一個新的1,否則不允許覆蓋腳本...)

function update_tpl2(form, divtoupdate, exeAlert) {
if(!$('#'+form).length)
    form = 'myform';
if(!$('#'+divtoupdate).length)
    divtoupdate = 'ajax_update';

$.ajax({
    type: "POST",
    url: url,
    data: $('#' + form).serialize(),
    dataType: "html",
    beforeSend: ShowLoading,
    success: function(resp){
        $('#theLoading').dialog('close');
        $('#loading').html('');         
        $('#' + divtoupdate).html(resp);
    }
});

}

並且我需要在運行時向該函數添加async:false。 有沒有辦法通過不更改功能並使用它來將ajax設置為async:false?

大概是這樣嗎?

只需使用properties = {async:false}調用以下函數

function update_tpl2(form, divtoupdate, exeAlert, properties) {
if(!$('#'+form).length)
    form = 'myform';
if(!$('#'+divtoupdate).length)
    divtoupdate = 'ajax_update';

var defaultProps = {
    type: "POST",
    url: url,
    data: $('#' + form).serialize(),
    dataType: "html",
    beforeSend: ShowLoading,
    success: function(resp){
        $('#theLoading').dialog('close');
        $('#loading').html('');         
        $('#' + divtoupdate).html(resp);
    }
}

jQuery.extend( true, defaultProps, properties)

$.ajax(defaultProps);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM