YUI对话框,表单提交成功后回调

YUI Dialog, callback after form submit is successful

本文关键字:回调 成功 表单提交 对话框 YUI      更新时间:2023-09-26

我有一个弹出对话框,使用YUI库发布表单,这是工作到目前为止。但是,在成功提交表单之后,我如何调用另一个函数呢?我基本上需要从刚刚由表单submit创建的数据库表行中拉出一个字段。

下面是我的代码:
 var callback = {
    success: function(result) {
        form = result.responseText;
        dialog = new YAHOO.widget.Dialog('dialog1', {
            width: '400px',
            fixedcenter : "contained",
            visible : false,
            draggable: true,
            effect:[{effect:YAHOO.widget.ContainerEffect.SLIDE, duration:0.2},
                    {effect:YAHOO.widget.ContainerEffect.FADE,duration:0.2}],
            modal:true
        });
        dialog.setHeader(titleval);
        dialog.setBody(form);
        var handleCancel = function() {
            this.cancel();
        };
        var handleSubmit = function() {
            date_box = dialog.getData().date;
            reason_box = dialog.getData().reason;
            hours = dialog.getData().date_start_hours;
            mins = dialog.getData().date_start_minutes;
            format = dialog.getData().format;
            ampm = dialog.getData().date_start_meridiem;
            username = dialog.getData().user;
            //basic validation
            if(date_box == '' && reason_box == '' ){
                document.getElementById('error1').style.display = "";
                document.getElementById('error2').style.display = "";
            }else if(date_box == '' || !isDate(date_box)){
                document.getElementById('error1').style.display = "";
                document.getElementById('error2').style.display = "none";
            }
            else if(reason_box == '' && !isDate(date_box)){
                document.getElementById('error1').style.display = "";
                document.getElementById('error2').style.display = "";
            }
            else if(reason_box == ''){
                document.getElementById('error1').style.display = "none";
                document.getElementById('error2').style.display = "";
            }
            else{
                 this.submit();
                 update(date_box, hours, mins, format, ampm, reason_box, username);
            }
        };
        var myButtons = [{ text: "Save", handler: handleSubmit, isDefault: true },
                         { text: "Cancel", handler:handleCancel }];
        dialog.cfg.queueProperty("buttons", myButtons);
        dialog.render(document.body);
        dialog.show();
        document.getElementById('call_id').value = id.value;
        eval(document.getElementById('script').innerHTML);
        eval(document.getElementById('script2').innerHTML);
    }
}
var connectionObject = YAHOO.util.Connect.asyncRequest ("GET", "index.php?entryPoint=Reschedule&call_id="+id.value, callback);

我相信这个页面包含答案:http://developer.yahoo.com/yui/container/dialog/

向下滚动到标题为"提交表单数据"的部分。它展示了如何配置回调。