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?
Magento Stack Exchange is a question and answer site for users of the Magento e-Commerce platform. It only takes a minute to sign up.
Sign up to join this communityWe 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();
}
);
}
});
}
);