简体   繁体   English

向mysql添加空记录的Javascript代码

[英]Javascript code adding empty records to mysql

I have a short problem.我有一个简短的问题。 Here is my form layout:这是我的表单布局:

    <form class="form-inline" action="javascript:addRecord();" method="GET">
    <div class="row">
        <div class="form-group col-lg-4">
            <div class="form-group col-lg-6">
                <label for="konu">Konu:</label> 
                <input class="form-control " type="text" name="konu" required="required" placeholder="Bir konu yazın"/>
            </div>                                                                          
        </div>                                                        
    </div>  
    <br>                          
    <div class="form-group col-lg-5 ">
        <button type="submit" class="btn btn-default">Kaydet</button>  
    </div>                            
</form>

    <div id="add-record-div" class="alert alert-success" hidden="hidden">
         <strong>RECORD INSERTED</strong>    
    </div>

And my javascript code:还有我的 javascript 代码:

function addRecord() 
{                   
    $.post('add.php', function(data) 
    {    
        trHTML += 
        '<tr><td>' + value.id + 
        '</td><td>' + value.konu + 
        '</td><td>' + value.aciklama + 
        '</td><td>' + value.giris_tarih + 
        '</td><td>' + value.degistirilme_tarih + 
        '</td><td>' + value.ad_soyad + 
        '</td><td>' + value.email + 
        '</td></tr>';     
    });

    getLastRecord();       
    $('#add-record-div').show('slow').delay('1000'); 
    $('#add-record-div').hide('slow');                                                  
}

Databse insert looks like this: http://i.stack.imgur.com/fDiiC.jpg My problem is this function adds only empty rows to mysql.数据库插入看起来像这样: http : //i.stack.imgur.com/fDiiC.jpg我的问题是这个函数只向 mysql 添加空行。 ' giris_tarih ' and 'degistirilme_tarih' are date values. ' giris_tarih ' 和'degistirilme_tarih'是日期值。 Those are being added correctly but other columns are always empty.这些被正确添加,但其他列始终为空。 There is no problem with add.php page. add.php页面没有问题。 If I only write: form class="form-inline" action="add.php" it works perfectly.如果我只写: form class="form-inline" action="add.php"它可以完美运行。 But I couldn't get it worked with javascript function.但我无法让它与 javascript 函数一起工作。

You have mismatched actions in your markup and script, and also your data is pointing to value which is not part of the object returned from your add.php (you set your ajax response to the variable data , therefore you must use data.propName... ).您的标记和脚本中的操作不匹配,并且您的数据指向的值不是从add.php返回的对象的add.php (您将 ajax 响应设置为变量data ,因此您必须使用data.propName... )。 I also corrected your table formatting a bit and used jQuery like the rest of your module.我还稍微更正了您的表格格式,并像使用模块的其余部分一样使用了 jQuery。

function addRecord() 
{                   
    $.get('add.php', function(data) 
    {    


        $('#your-table').append('<tr>' + data.id + '</td>'
        + '<td>' + data.konu + '</td>'
        + '<td>' + data.aciklama + '</td>'
        + '<td>' + data.giris_tarih + '</td>'
        + '<td>' + data.degistirilme_tarih + '</td>'
        + '<td>' + data.ad_soyad +  '</td>'
        + '<td>' + data.email + '</td>'
        + '</tr>');

    getLastRecord();       
    $('#add-record-div').show('slow').delay('1000'); 
    $('#add-record-div').hide('slow');                                                  
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM