doupian6118 2014-02-20 23: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 23: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条)

报告相同问题?

悬赏问题

  • ¥15 mmocr的训练错误,结果全为0
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀