Particular case: Programmed Query string using form inside dialog

断了今生、忘了曾经 提交于 2019-12-01 18:17:38

I changed your jsFiddle to get a few things working, but it's probably still not the way you want it:

jsFiddle.

I added jQuery and jQuery-ui to your jsFiddle so it would compile, and put an alert stub in where you should put your form submission code.

Your .submit() handler was not getting called because the add and cancel buttons are added by the jquery-ui .dialog(...) invocation and are not part of the <form> element.

If you put your ajax code in the "Add" button function handler you should be good to go. I don't know what most of your code does, but this might at least help.

var regex,v,l,c,b,i,contapara=3;
$( "#wnd_Addparam" ).dialog({
    autoOpen: false,
    height: 'auto',
    width: 350,
    modal: true,
    resizable:false,
    buttons: {
        "Add": function() {
            contapara=(parseInt(contapara)+1);
            alert("add was clicked");
            // to use ajax uncomment below, depending on the 
            // service you're hitting, you may need
            // to change it to $.get(... etc 
            // which will use HTTP GET verb
            /*
            var $fm = $("#formparam");
            $.post($fm.attr('action'), $fm.serializeArray())
                .done(function(data, ok){
                    alert('call done: ' + ok);
                    // data is the content of the response
                })
                .fail(function(data){
                    alert('call failed');
                    // call failed for some reason -- add error messaging?
                });                            
            */
            $( this ).dialog( "close" );
        },
        Cancel: function() {
            $( this ).dialog( "close" );
        }
    }
});

$( "#btn_Addpar" ).click(function() {
                i=(parseInt(contapara)+1);
                $("#formparam").remove();
            $("#wnd_Addparam").append('<form method="GET" name="formparam"  id="formparam" action="${nextstep}"><table><tr><td><label>ID</label></td><td>\
            <textarea class="expand" name="inputp'+i+'_id" id="inputp'+i+'_id"></textarea></td></tr>\
            <tr><td><label>Type</label></td><td><select name="inputp'+i+'_type" id="inputp'+i+'_type">\
            <option value="text">Text</option><option value="integer">Integer</option><option value="float">Float</option>\
            <option value="list_values">List of values</option><option value="range">Range</option>\
            <option value="selection_collapsed">Selection (collapsed)</option>\
            <option value="selection_expanded">Selectionddddd (expanded)</option>\
            <option value="subimage">Subimage selectiondddddd</option>\
            <option value="polygon">Polygon selectionddd</option>\
            <option value="horizontal_separator">Horizontal separator</option>\
            </select></td></tr></table></form>');


        $( "#wnd_Addparam" ).dialog( "open" );
    }); ​

You are getting the "too much recursion" error because of this line:

close: function () {
    $(this).dialog("close");
}

What you are saying here is that when the dialog is closed, you should close the dialog, which fires this handler in an infinite loop. Comment out this line or just remove it completely.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!