-1
いつでも私はajaxを使ってPHPページにデータをポストしようとします。チェックされていない場合は、チェックボックスの値をPHPページに渡したくありません。これは、スクリプト2(以下を参照)で行ったことです。私が今したいのは、チェックボックスがチェックされていない場合、チェックボックスとテキストフィールドの両方をPHPページに渡すことなく、値なしでデータを渡すためにjavascript ajaxポストコードを使用することです。おかげで、私は任意の助けチェックボックスのAjaxポストデータとテキストフィールドのポストデータを1つのコードで結合しようとしています
HTML
<form action="altupdatenew" method="POST" class="alt">
<input type="checkbox" class="p_name" name="p_name" value="1" /> Checkbox 1 <br />
<input type="checkbox" class="s_name" name="s_name" value="1"> Checkbox 2 <br />
<input type="text" name="custome_text" class="form-control" placeholder="text" value=""> text field <br />
ジャバスクリプト1
$('form.alt').on('submit', function(){
var that = $(this),
url = that.attr('action'),
type = that.attr('method'),
data = {};
//console.log(that.find('input'))
that.find('input[name]').each(function(index, value){
//console.log(value);
var that = $(this),
name = that.attr('name'),
value = that.val();
data[name] = value;
//console.log(value);
});
$.ajax({
url: url,
type: type,
data: data,
success: function(respones){
console.log(respones);
$.notify({
icon: 'pe-7s-angle-up-circle',
message: "Test <b> Notification </b> Updated"
},{
type: 'info',
timer: 4000
});
}
});
return false;
})のために感謝するだろう。
javascriptの2
$('form.alt').on('submit', function(){
data = {};
var that;
var that1;
$('.p_name').each(function(){
if($(this).is(":checked"))
{
that = $(this).val();
}
});
$('.s_name').each(function(){
if($(this).is(":checked"))
{
that1 = $(this).val();
}
});
data = [that,that1];
$.ajax({
url:"altupdatenew_PS",
method:"POST",
data:{p_one:that,s_one:that1},
success: function(respones){
console.log(respones);
}
});
console.log(data);
return false;
});
あなたの必要性は何ですか? あなたの質問は明確ではありません... !!! – anuraj
私はちょうど私の質問を書き直しました – adjoke