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 网络科学导论,网络控制
  • ¥15 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)