-1

ビューからコード イグナイター モデルに ajax/jquery を使用してフォームを送信しようとしています。post 値がモデルに渡された場合、true を返します。

私の見解は関係なく成功メッセージを表示しています。誰かが私が間違っているところを指摘してもらえますか?

これが私のコントローラーの機能です:

function bookings(){
            $this->load->helper('url');
            if($_POST):
                 echo $_POST["name"];

            // do database stuff here to save the comment.

            // return false if db failed

            // else

            return true;

        endif;
}

ビューからの関連するJavaScriptとフォームは次のとおりです。

<div id="booking-form-container" class="fb-dialogue">
            <div id="info">Entery your details below to make a group booking:</div>

            <!-- This will hold response / error message from server -->
            <div id="response"></div>

            <form id="bookingsform" method="post" action="eventguide/bookings">

                <label class="description" for="element_1">Full Name: </label>
                <div>
                    <input id="name" name="name" class="element text medium" type="text" maxlength="255" value="<?php echo $me['first_name'] . ' ' . $me['last_name']; ?>"/> 
                </div> 

                <label class="description" for="element_2">Email: </label>

                <div>
                    <input id="element_2" name="element_2" class="element text medium" type="text" maxlength="255" value="<?php echo $me['email']; ?>"/> 
                </div> 

                <label class="description" for="element_3">Mobile Number: </label>
                <div>
                    <input id="element_3" name="element_3" class="element text medium" type="text" maxlength="255" value=""/> 
                </div> 

                <label class="description" for="element_5">Choose You're Event: </label>
                <div>
                    <select class="element select medium" id="element_5" name="element_5"> 
                        <option value="" selected="selected"></option>
                        <option value="1" >First option</option>
                        <option value="2" >Second option</option>
                        <option value="3" >Third option</option>

                    </select>
                </div> 

                <label class="description" for="element_4">Group Size: </label>
                <div>
                    <input id="element_2" name="element_4" class="element text medium" type="number"  value="10"/> 
                </div> 

                <label class="description" for="element_6">Questions or Special Requirements? </label>
                <div>
                    <textarea id="element_6" name="element_6" class="element textarea medium"></textarea> 
                </div> 

            </form>
        </div>

        <script type="text/javascript">

            var mydetails = $("#booking-form-container").dialog({autoOpen: false, modal: true, draggable: true, resizable: false, bgiframe: true, width: '400px', zIndex: 9999, position: ['50%', 100]});

            function showDetailsDialog() {

                $("#booking-form-container").dialog("option", "title", "Group Bookings");


                $("#booking-form-container").dialog({buttons: {
                        "Close": {text: 'Close', priority: 'secondary', class: 'btn', click: function() {
                                $(this).dialog("close");
                            }},
                        "Confirm Booking": {text: 'Confirm Booking', priority: 'primary', class: 'btn btn-primary', click: function() {
                                $('#bookingsform').submit();
                            }}
                    }
                });
                $("#booking-form-container").dialog("open");

            }

            $("#bookingsform").submit(function(event) {
                event.preventDefault();


                dataString = $("#bookingsform").serialize();

                     $.ajax({
                       type: "POST",
                       url: "<?php echo base_url(); ?>eventguide/bookings",
                       data: dataString,

                       success: function(data){
                           alert('Successful!');
                       }

                     });

                     return false;  //stop the actual form post !important!
            });

        </script>  
4

3 に答える 3

0

あなたは誰に忠実に戻っていますか?エコーしたメッセージは $_POST['name'] であるクライアント側に戻りますが、PHP コードで true が返されると、サーバー側で bi になります。私の意見では、 codeigniter を使用しているため、 $this->input->post('name'); を使用する必要があります。純粋な php ポスト サーバー変数の代わりに。

于 2013-08-20T03:24:28.960 に答える
0

$_POST["name"] が設定されていないと思います。コードを変更する必要があると思います

$.ajax({ type: "POST", url: "eventguide/bookings", data: { 'name' :dataString}, success: function(data){ alert('Successful!'); } });

サーバー側でキャッチしたい変数に名前が付けられていません。

于 2013-08-20T20:55:57.210 に答える