gpt4 book ai didi

javascript - 如何通过ajax发送复选框值: either true or false,

转载 作者:可可西里 更新时间:2023-11-01 13:48:27 24 4
gpt4 key购买 nike

我想使用 ajax 将复选框的值发送到数据库。通过在互联网上的一些搜索,我以某种方式设法做到了这一点。这就是我一直在使用的。我需要对 json2.stringify 进行哪些更改才能正确发送我的值。

HTML:

<input type="checkbox" id="txtCategoryIsPaid" name="cateogryIsPaid" value="Paid">Yes<br>

Javascript:

AddCategory: function () {                
BusinessManagement.config.method = "AddBusinessCategory";
BusinessManagement.config.url = BusinessManagement.config.baseURL + BusinessManagement.config.method;
BusinessManagement.config.data = JSON2.stringify({

CategoryIsPaid: $('#txtCategoryIsPaid :checked').val(),

});
BusinessManagement.config.ajaxCallMode = 0;
BusinessManagement.ajaxCall(BusinessManagement.config);

最佳答案

使用.prop('checked')属性

<HTML>
<input type="checkbox" id="txtCategoryIsPaid" name="cateogryIsPaid" value="Paid">Yes<br>

Javascript
AddCategory: function () {
BusinessManagement.config.method = "AddBusinessCategory";
BusinessManagement.config.url = BusinessManagement.config.baseURL + BusinessManagement.config.method;
BusinessManagement.config.data = JSON2.stringify({

CategoryIsPaid: $('#txtCategoryIsPaid').prop('checked') == true ? "true": "false",

});
BusinessManagement.config.ajaxCallMode = 0;
BusinessManagement.ajaxCall(BusinessManagement.config);

关于javascript - 如何通过ajax发送复选框值: either true or false,,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38565212/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com