weixin_33709609 2014-04-15 11:38 采纳率: 0%
浏览 33

使用AJAX将行添加到数据库

I have script that add test/row to the DB with AJAX

I added checkbox (#main) and I want it to be sent to the db too.

For some reseaon, checked or not, the checkbox always send me the same value to the DB Why is that?

//##### send add record Ajax request to response.php #########
$("#FormSubmit").click(function (e) {
    //  e.preventDefault();
        if($("#contentText").val()==='')
        {
            alert("Please enter some text!");
            return false;
        }
        alert($("#main").val());
        var myData = 'content_txt='+ $("#contentText").val() + "&main= " + $("#main").val(); //build a post data structure
        jQuery.ajax({
        type: "POST", // HTTP method POST or GET
        url: "response.php", //Where to make Ajax calls
        dataType:"text", // Data type, HTML, json etc.
        data:myData, //Form variables
        success:function(response){
            $("#responds").append(response);
            $("#contentText").val(''); //empty text field on successful
        },
        error:function (xhr, ajaxOptions, thrownError){
            alert(thrownError);
        }
        });
});

<div class="form_style">
    <textarea name="content_txt" id="contentText" cols="45" rows="5"></textarea>
    <input type="checkbox" name="main" id="main" />
    <button id="FormSubmit">Add record</button>
</div>
  • 写回答

4条回答 默认 最新

  • 妄徒之命 2014-04-15 11:41
    关注

    Use for checkbox element .is(':checked')

    Example for your code:

    $('#main').is(':checked');
    
    评论

报告相同问题?

悬赏问题

  • ¥15 三菱变频器模块怎么检测触发
  • ¥30 求一下解题思路,完全不懂。
  • ¥30 关于#硬件工程#的问题:求一下解题思路
  • ¥15 运筹学对偶单纯行法构造扩充问题
  • ¥20 XP系统的老电脑一开机就提示找不到rundll.exe,付费求解
  • ¥15 milvus查询出来的score怎么转换成0-1之间的相似性
  • ¥15 lvgl V9移植到linux开发板
  • ¥15 VB.net中在窗体中创建一个button控件来关闭窗体,但是提示错误,我该怎么办
  • ¥15 网上下载好的程序但是arduinoIDE编程报错,运行不了,哪里出错了,能具体给改一下吗
  • ¥15 Sharepoint JS开发 付费技术指导