繁体   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