0

送信する必要のあるデータを含む次のフォームがあります。

<form action="http://localhost/sp/index.php/daily_operation/turn_close" method="post" accept-charset="utf-8" id="form" name="form" class="form_cash"><br />           <input type="hidden" id="total_amount" name="total_amount" value="0">

                  <div>
                  <fieldset class="fieldset">

                  <legend>Billetes</legend>
                  <div class="row_form_div">
                      <label for="hundred_amount">100</label>
                      <input type="text" id="hundred_amount" name="hundred_amount" class="billet"/>
                      <input type="hidden" id="hundred_denomination_id" name="hundred_denomination_id" value="1">
                  </div>

                  <div class="row_form_div">
                      <label for="fith_amount">50</label>
                      <input type="text" name="fith_amount" id="fith_amount"  class="billet"/>
                      <input type="hidden" id="fith_denomination_id" name="fith_denomination_id" value="2">
                  </div>

                  <div class="row_form_div">
                      <label for="twenty_amount">20</label>
                      <input type="text" name="twenty_amount" id="twenty_amount" class="billet"/>
                      <input type="hidden" id="twenty_denomination_id" name="twenty_denomination_id" value="3">
                  </div>

                  <div class="row_form_div">
                      <label for="ten_amount">10</label>
                      <input type="text" name="ten_amount" id="ten_amount" class="billet"/>
                      <input type="hidden" id="ten_denomination_id" name="ten_denomination_id" value="4">
                  </div>

                  <div class="row_form_div">
                      <label for="five_amount">5</label>
                      <input type="text" name="five_amount" id="five_amount" class="billet"/>
                      <input type="hidden" id="five_denomination_id" name="five_denomination_id" value="5">
                  </div>

                  <div class="row_form_div">
                      <label for="one_amount">1</label>
                      <input type="text" name="one_amount" id="one_amount" class="billet"/>
                      <input type="hidden" id="one_denomination_id" name="one_denomination_id" value="6">
                  </div>

                 </fieldset>
                 </div>
</form>

送信する前に、フォームのデータを使用して条件を尋ねる必要があります。条件を尋ねるためにjqueryuiダイアログを作成します

<div id="dialog-confirm" title="&iquest;Cerrar turno con diferencia?">
            <p><span class="ui-icon ui-icon-alert" style="float:left; margin:0 7px 20px 0;">
            </span>El desglose insertado no coincide con el total por concepto de operaciones. Esto significa que cerrar&aacute; el turno con diferencia. 
            &iquest;Est&aacute; seguro?</p>
        </div>

次のJQueryコードで呼び出します。

$( "#dialog-confirm" ).dialog({
    resizable: false,
    autoOpen:false,
    height:150,
    width:340,
    open:false,
    modal: true,
    buttons: {
        "No": function() {
            $( this ).dialog( "close" );
        },
        "Si": function() {
                $("#form").submit();
                $(this).dialog('close');
                }
        }
    }
});

これは、フォームに投稿されたデータを送信することを目的としていますが、何も起こりません。

私もAjaxでこれをやろうとしました

        "Si": function() {
                $("#form").submit();
                if (true) {
                    {
                        $.ajax({
                            type: "POST",
                            dataType: "json",
                            url: 'daily_operation/turn_close',
                            data: $("#form").serialize(), // serializes the form's elements.
                            success: function(data)
                            {
                            },
                            error: function(data) {
                                bValid = false;
                            }
                        });

                    }
                    $(this).dialog('close');
                }
        }

しかし、何も送信せずに残ります。

手伝っていただけませんか?前もって感謝します...

4

2 に答える 2

0

The question is if you are trying to send it traditional way or by using AJAX

$("#form").submit();

This should send it but there are some problems (eg. IE requires that form contains submit button sic!). And this approach can create many problems. What i suggest is to use AJAX. For start try and see what happens. :

$.ajax({
                            type: "POST",
                            dataType: "json",
                            url: 'daily_operation/turn_close',
                            data: $("#form").serialize(), 
                            beforeSend : function(){
                                  alert($("#form").serialize());
                            },
                            success: function(data)
                            {
                                 alert(data);
                            },
                            error: function(data) {
                                bValid = false;
                            }
                        });
于 2012-10-31T20:19:03.267 に答える
0

これが古い投稿であることはわかっていますが、フォームが送信されなかった理由はわかっていると思います。それ以外の

$("#form").submit();

そのはず

$("#form")[0].submit();.

.submit()form実際のHTML 要素の組み込み JavaScript 関数です。実際の要素で使用する必要があります。純粋な JS の場合:

document.getElementById("form").submit();

jQueryは、関数をイベント.submit()にアタッチするために使用されます。submitお気に入り:

$("#form").submit(function() { 
   return true; 
});

jQuery では、.get()関数または配列インデックスのいずれかを使用して、実際の HTML 要素を取得できます。したがって、この:

$("#form").get(0).submit();

も動作するはずです。

于 2013-10-20T03:42:14.643 に答える