2016-07-25 40 views
3

我想使用ajax將我的複選框的值發送到數據庫。通過在互聯網上進行一些搜索,我以某種方式設法得到了這一點。這是我一直在使用的。我需要對json2.stringify進行哪些更改才能正確發送我的值。如何通過ajax發送複選框值:true或false通過ajax

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); 
+1

'$( '#txtCategoryIsPaid')是( ':檢查')。' – Tushar

回答

1

使用.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); 
+0

感謝你shubham.this解決了我的問題。 btw是你從尼泊爾嗎?也可以分享一些鏈接,可以解決一些其他類似的問題選擇和圖像類型? –

+0

@BibekAryal你在找什麼類型的鏈接。順便說一句,我不是來自尼泊爾。 –

+0

我仍然需要發送html「select」的值以及「image」的文件路徑。所以我想知道是否有一個網站與所有這些集體信息? –