'How can i fix 400 (Bad Request) jquery ajax in wordpress?
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 $row['attributes'] it has (size,brand,color......)
<form id="form">
<?php foreach($rows as $row): ?>
<fieldset>
<?php
$result_attributes = get_terms([
'taxonomy' => $row['attributes'],
'hide_empty' => false,
]);
?>
<select id="select-wid" name="<?php echo $row['attributes']?>">
<option value="">Select</option>
<?php foreach($result_attributes as $result_attribute) : ?>
<option value="<?php echo $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: ajaxwp.ajax_url,
data: {action: 'myactionfunction', data:data},
type: 'post',
success: function(result) {
$('.products').html(result);
},
error: function(result) {
console.warn(result)
},
});
});
});
})(jQuery);
Image from console: ErrorConsoleImage Image from PHP: ErrorPhP
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
