I'm using custom js in Product Add/Edit page of magento 2 admin. I need to make a ajax call when the product save button clicked. I used the below code.
require(['jquery', 'domReady!'], function ($) {
$(document).ajaxComplete(function () {
let data = '';
varr.forEach((i, j) => {
if (i.length > 0) {
data = JSON.stringify({
"data": {
"sku": sku,
"brand": i[0].brand,
"variant": i[0].variant,
"vehicle_type": "car",
"model": i[0].model
}
});
}
var settings = {
"async": true,
"crossDomain": true,
"url": "http://192.168.2.196/motogaadi/rest/V1/garage/garage_sku_insert/",
"method": "POST",
"headers": {
"Content-Type": "application/json",
"Cache-Control": "no-cache",
"cache-control": "no-cache"
},
"processData": false,
"data": data
}
$.ajax(settings).done(function (response) {
console.log(response);
});
});
});
});
I am receiving the below issue.
POST http://192.168.2.196/motogaadi/rest/V1/garage/garage_sku_insert/?isAjax=true 400 (Bad Request)
The same Ajax call is working in frontend but not in adminhtml.