Friends, I’m converting Jquery to javascript and I’m having problems with this block of code:
$.post('ajax_data',{action:'service_price',service:service,quantity:quantity,dripfeed:dripfeed,runs:runs}, function(data){
$("#charge").val(data.price);
$("#dripfeed-totalquantity").val(data.totalQuantity);
}, 'json');
I tried to do this, but it doesn’t work for me
const request = new XMLHttpRequest();
const url = "ajax_data";
const params = "action=service_price&service=" + service + "&quantity=" + quantity+ "&dripfeed=" + dripfeed+ "&runs=" + runs;
request.responseType = "json";
request.open("POST", url, true);
request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
request.addEventListener("readystatechange", () => {
if (request.readyState === 4 && request.status === 200) {
let data = request.response;
document.querySelector("#charge").val(data.price);
document.querySelector("#dripfeed-totalquantity").val(data.totalQuantity);
}
});
request.send(params);
2
Answers
I solved it this way:
Here: