Ajax调用选择框中的多选

时间:2011-02-24 12:03:15

标签: jquery

如何在选择框中选择多个值时调用Jquery Ajax。

此致 拉吉

2 个答案:

答案 0 :(得分:2)

我使用这种方法,只有你可以在帖子中看到更多:

Using jQuery, how do you mimic the form serialization for a select with multiple options selected in a $.ajax call?

 var mySelections = [];
        $('#mySelect option').each(function(i) {
                if (this.selected == true) {
                        mySelections.push(this.value);
                }
        });


    $.ajax({
      type: "post",
          url: "http://myServer" ,
          dataType: "text",
          data: {
                'service' : 'myService',
                'program' : 'myProgram',
        'selected' : mySelections
                },
          success: function(request) {
                result.innerHTML = request ;
      }
    }); // End ajax method

答案 1 :(得分:-1)

public static boolean display(String titolo,String messaggio){

    Dialog<Boolean> dialog = new Dialog<>();
    dialog.setTitle(titolo);
    dialog.getDialogPane().setContentText(messaggio);
    dialog.getDialogPane().getButtonTypes().addAll(
        ButtonType.YES, ButtonType.NO);

    // Result of dialog is true if button is YES button, 
    // false otherwise
    dialog.setResultConverter(button -> button == ButtonType.YES);

    // return result of dialog, or false if there is no result
    // (i.e. if user closes dialog without pressing a button)
    return dialog.showAndWait().orElse(false);
}