doupian6118 2014-02-20 15:06
浏览 22
已采纳

ajax - 没有数据传输

I am a newbie on ajax. I spend hours with "try and error", but unfortunately without success.

I have a form:

<form id="upload" method="post" name="form">
    <input class="datepicker" type="text" name="date" value="<?php echo $date_bes; ?>"/>
    <input class="chk" name="chk" type="checkbox" value="<?php echo $id_submit; ?>"
    <?php if($check == 1){ echo "checked"; }else{ echo "";} ?>/>
    <textarea class="remark" name="remark" cols="30" rows="1"><?php echo $remark; ?> </textarea>
    <input class="submit" type="image" src="save.jpg"></td>
    </form>

Then I my ajax_script.js:

$(document).ready(function() {      
    $( "#upload" ).on("submit", function() {

        var id = $('.chk').val();
        var date = $('.datepicker').val();
        var chk = $('.chk').prop('checked');
        var remark = $('.remark').val();

        $.ajax({
            type: "POST",
            url: "update.php",
            data :   "{'id':'" + id + "', 'date':'" + date + "', 'chk':'" + chk + "', 'remark':'" + remark + "'}",
            success: function (data) {
            if(data.success == true)
            {
                console.log('everything fine');
            }
            },
            error: function(){
                console.log('something bad happened');

            }

         });
});

    });

and my update.php

<?php
    $id = $_POST['id'];
    $date = $_POST['date'];
    $chk = $_POST['chk'];

    if($chk == true){
    $check = 1;
    }else{
    $check = 0;
    }

    $remark = $_POST['remark'];

        $jahr = substr($date,6,4);
        $mon  = substr($date,3,2);
        $tag  = substr($date,0,2);
        $date = $jahr.'-'.$mon.'-'.$tag;

    echo $id ."<br>".$date."<br>".$chk."<br>".$remark;

    require_once('config.php');

    $link = mysqli_connect (
                         MYSQL_HOST, 
                         MYSQL_BENUTZER, 
                         MYSQL_KENNWORT, 
                         MYSQL_DATENBANK
                        );

    if(!$link){
        die('Keine Verbindung möglich: ' .mysql_error());
    }
    $sql = "UPDATE mytable
    SET date = '$date', chka ='$chk', remark = '$remark' WHERE id_submits = $id";
    $result = mysqli_query( $link, $sql );
    echo $sql."<br>";
    ?>

After push on the bottom, firebug deliver me following:

enter image description here

Can anybody help me - please!

Regards, Yab86

展开全部

  • 写回答

2条回答 默认 最新

  • douping5226 2014-02-20 15:24
    关注

    I think that you do not really need the quotes around the variable in the data section of ajax.

    data: {id: id, date: date, chk: chk, remark: remark},
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)
编辑
预览

报告相同问题?