We have one button on checkout page to find address from our
API. We want to send one ajax request to that API to get some data.
How do we send ajax request from knockout js?
We have one button on checkout page to find address from our
API. We want to send one ajax request to that API to get some data.
How do we send ajax request from knockout js?
Use mage/storage for ajax call in knockoutjs
define(
[
...
'mage/storage'
...
],
function(
...
storage
...
) {
return Component.extend({
...
/** Your function for ajax call */
myAjaxCall: function(dataToPass) {
fullScreenLoader.startLoader();
storage.post(
'url/of/mycontroller',
JSON.stringify(dataToPass),
true
).done(
function (response) {
/** Do your code here */
alert('Success');
fullScreenLoader.stopLoader();
}
).fail(
function (response) {
fullScreenLoader.stopLoader();
}
);
}
});
}
);