0

クリック時に4つのフィールドを保存したい1つはテキストボックス2つのチェックボックスで、1つはajaxを使用したwysihtml5Editorです。これらは次のとおりです。

<input type="text" id="title" name="title" required title="required" placeholder="title" data-bind="value:title" />
<input type="checkbox" id="active" name="active" class="check" data-bind="checked: active=='true'"  />Active
<input type="checkbox" id="logon" name="logon" class="check" data-bind="checked: use_logo=='true'"  />Logo
<textarea id="iiii" name="iiii" class="htmleditor" rows="9" cols="50" style="width: 600px; height: 190px;"></textarea>
<button type="button" name="save" id="save" class="btn btn-primary">Save</button> 

私のテーブル名はcontracts次のとおりです。フィールド名は次のとおりです。

title(textbox),def_next(wysihtml5Editor),active(checkbox),use_logo(checkbox)

そして私は次のような条件でそれをやっています:

if ($_POST['what']=="save"){} 

そして私はajaxを

$.ajax({
        type: 'POST',
        url: root + 'data/comapanydata_contractorslist?json',
        data: {
            what: "save",
            text: $('#iiii').val(),
            def_text: def_text
        },
        success: function (data) {},
        dataType: 'json'
    });

しかし、動作していないので、これについて私に提案してください。

4

2 に答える 2

0

4 つのフィールドすべてを保存する場合は、それらすべてからサーバー サイド スクリプトにデータを転送する必要があります。多分このようなもの:

$.ajax({
    type: 'POST',
    url: root + 'data/comapanydata_contractorslist?json',
    data: {
        what: "save",
        def_text: $('#iiii').val(),
        title: $('#title').val(),
        active: $('#active').val(),
        use_logo: $('#logon').val()
    },
    success: function (data) {},
    dataType: 'json'
});
于 2013-01-31T12:50:58.023 に答える
0

これは私のために働く:

index.html

            <script>
            $(function() {                  
                $("#form").submit(function() {
                    data = $("#form").serialize();
                    $.ajax({
                        type : "GET",
                        url : "save-data.php",
                        data : data,
                        success : function() {
                            $("#form").find("input[type=text], textarea").val("")
                            $("#form").find("input[type=checkbox]").prop('checked', false); 
                        }
                    });
                    return false;
                });
            });
            </script>

            <form action="save-data.php" method="get" id="form">
                <input type="text" id="title" name="title" required title="required" placeholder="title" data-bind="value:title" />
                <input type="hidden" name="active" value="off" />
                <input type="checkbox" id="active" name="active" class="check" data-bind="checked: active=='true'" />Active                 
                <input type="hidden" name="logon" value="off" />
                <input type="checkbox" id="logon" name="logon" class="check" data-bind="checked: use_logo=='true'" />Logo
                <textarea id="iiii" name="iiii" class="htmleditor" rows="9" cols="50" style="width: 600px; height: 190px;"></textarea>
                <input type="submit" name="save" id="save" value="Save" class="btn btn-primary"/>
            </form>

変数への入力の保存:

保存-data.php

        <?php 
            $required = array('title', 'iiii', 'active', 'logon');
            $error = false;
            foreach ($required as $field) {
                if (empty($_GET[$field])) {
                    $error = true;
                }
            }

            if (isset($_GET["title"])) {
                if ($error) {
                    echo "All fields are required.";
                } else {
                    $title = $_GET["title"];
                    $active = $_GET["active"];
                    $logon = $_GET["logon"];
                    $iiii = $_GET["iiii"];

                       //mysql query ...
                }
            }
        ?>
于 2013-01-31T12:33:34.803 に答える