weixin_33717298 2016-04-23 05:32 采纳率: 0%
浏览 57

jQuery Ajax触发两次

for some reasons the function is being triggered twice. also if you can help me improve the codes (am a noobz) that would be highly appreciated.

the main calling function will be: get_range_entries

once the callback returns the status it displays the modal box but somehow it goes to the next lines of code so its preventing me from closing the modal window.

function load_XMLDoc(dname, callback) {
    $.ajax({
        cache: false,
        type: 'GET',
        dataType: "xml",
        url: dname + '&date=' + new Date().getTime(),
        success: function(result) {
            if(typeof callback === "function") {
                callback(result)
            }
        }
     })
}


function get_range_entries(view_name, startkey, universal_id, column, callback) {
    //unid = universal id
    //column = column number to compare
    //this is for uncategorized views only

    var url;
    var status = false;

    url = view_name + '?ReadViewEntries&ResortAscending=' + column + '&StartKey=' + startkey + '&UntilKey=' + startkey + 'Z&ExpandView';
    load_XMLDoc(url, function(result) {
        viewentries = result.getElementsByTagName("viewentries");
        entries = result.getElementsByTagName("viewentry");
        range_entries = viewentries[0].getAttribute('rangeentries');

        if (range_entries == 0) {
            status = false;
        }
        else {          
            entries = result.getElementsByTagName("viewentry");
            columns  = entries[0].getElementsByTagName("entrydata");

            if (entries[0].getAttribute('unid')) {
                unid = entries[0].getAttribute('unid');
            }

            if (unid == universal_id)
                status = false;
            else {
                colvalue = columns.item(column).childNodes[1].firstChild.nodeValue;
                status = (colvalue.toLowerCase() == startkey.toLowerCase());
            }
        }
        alert(1); ------------------> just using this to check if its being triggered twice
        callback(status);
    })
}



function display_message_string(message_title, message_string, hide_primary) {  
    $('#modal-confirm').find('.modal-title').html(message_title);
    $('#modal-confirm').find('.modal-body').html(message_string);

    if (hide_primary)
        $('#modal-confirm').find('.btn-primary').hide();
    else
        $('#modal-confirm').find('.btn-primary').show();

    $('#modal-confirm').modal('show');      
}



get_range_entries(view_name, startkey, unid, 1, function(status) {
        if (status) {
            display_message_string("DUPLICATE ENTRIES ENCOUNTERED", "The GENERATOR NAME you are trying to save already exists in the Database ... Please try again", true);
            return false; ----> added this just to prevent it from triggering twice but it doesn't seem to work
        }
})

..... next lines of code to save the form

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥30 这是哪个作者做的宝宝起名网站
    • ¥60 版本过低apk如何修改可以兼容新的安卓系统
    • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
    • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
    • ¥50 有数据,怎么用matlab求全要素生产率
    • ¥15 TI的insta-spin例程
    • ¥15 完成下列问题完成下列问题
    • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
    • ¥15 YoloV5 第三方库的版本对照问题
    • ¥15 请完成下列相关问题!