我有两个Ajax表单来过滤WordPress网站上的文章。这两种方式都是分别过滤好的。
Here is the link Test Server
现在我试着把这两者合并成一个,然后以One form形式作为呈现结果。该如何将2个Ajax表单合并为1个??
Script form:1
jQuery(document).ready(function($){
$('#test .br').click(function(){
// declaring an array
var choices = {};
$('.contents').remove();
$('.filter-output').empty()
console.log(choices);
$.ajax({
url: ajaxobject.ajaxurl,
type :'POST',
data : {
'action' : 'call_post',
'choices' : choices,
},
success: function (result) {
$('.filter-output').append(result);
}
});
})
});
Script Form:2
jQuery(function($){
$('#filter').submit(function(){
var filter = $(this);
$.ajax({
url:filter.attr('action'),
data:filter.serialize(), // form data
type:filter.attr('method'), // POST
beforeSend:function(xhr){
filter.find('button').text('Processing...'); // changing the button label
},
success:function(data){
filter.find('button').text('Apply filter'); // changing the button label back
$('#response').html(data); // insert data
}
});
return false;
});
});