Hello guys I have a problem when I’m trying to send data by ajax and it’s said that I have 400 (Bad Request) ajax errors and this is my code:
This is Html code:
the rows is data of my database
<form id="form">
<?php foreach($rows as $row): ?>
<fieldset>
<?php
$result_attributes = get_terms([
'taxonomy' => $row['attribute_woo'],
'hide_empty' => false,
]);
?>
<select id="select-wid" name="<?php echo esc_attr($row['attribute_woo'])?>">
<option value="">Select</option>
<?php foreach($result_attributes as $result_attribute) : ?>
<option value="<?php echo esc_attr($result_attribute->term_id); ?>"><?php echo ($result_attribute->name); ?>
</option>
<?php endforeach; ?>
</select>
</fieldset>
<?php endforeach;
This is jquery code:
(function($){
$(document).ready(function(){
$(document).on('change', '#form', function(e) {
var data = $(this).serialize();
e.preventDefault();
console.log(data);
$.ajax({
url: my_url,
data: data,
action: 'myactionfunction',
type: 'post',
success: function(result) {
$('.products').html(result);
},
error: function(result) {
console.warn(result)
},
});
});
});
})(jQuery);