2016-07-25 2 views
3

ajaxを使用して、自分のチェックボックスの値をデータベースに送信します。インターネットでの検索を通して、私は何とかこれを得ることができました。これが私が使ってきたものです。 json2.stringifyが正しく値を送信するためには、どのような変更を行う必要がありますか。チェックボックス値の送信方法: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あなたはどんなタイプのリンクを探していますか? btw私はネパール出身ではありません。 –

+0

私はまだhtml "select"の値と "image"のファイルパスを送らなければなりません。だから私は、これらのすべてに集合的な情報を持つサイトがあるのだろうかと思っていたのだろうか? –

関連する問題