Pause add to cart function after ajaxHow can I trigger code to run after knockoutjs render in adminhtmlExecute JavaScript code after swatches are displayed in category viewMagento2 - Customize Order Numbers - Overriding: MagentoSalesSequenceModelSequenceUnable to refresh the page after generating PDF file in order gridError cart message on AjaxSaving a value without triggering aftersave()Add to cart custom templateCall block action using Ajax
Please figure out this Pan digital Prince
2019 gold coins to share
Can you make an identity from this product?
Why is long-term living in Almost-Earth causing severe health problems?
Electricity free spaceship
Why does smartdiagram replace the Greek letter xi by a number?
What aircraft was used as Air Force One for the flight between Southampton and Shannon?
Can we completely replace inheritance using strategy pattern and dependency injection?
empApi with Lightning Web Components?
Fermat's statement about the ancients: How serious was he?
Proving that a Russian cryptographic standard is too structured
Are polynomials with the same roots identical?
A map of non-pathological topology?
Why is Na5 not played in this line of the French Defense, Advance Variation?
Analogy between an unknown in an argument, and a contradiction in the principle of explosion
Is there a set of positive integers of density 1 which contains no infinite arithmetic progression?
Why does this query, missing a FROM clause, not error out?
Is there a DSLR/mirorless camera with minimal options like a classic, simple SLR?
Getting UPS Power from One Room to Another
Why does a file move/copy function only move one file at a time when using the “*” wildcard?
What would prevent chimeras from reproducing with each other?
Do you need to let the DM know when you are multiclassing?
Should I put programming books I wrote a few years ago on my resume?
What are the implications when matrix's lowest eigenvalue is equal to 0?
Pause add to cart function after ajax
How can I trigger code to run after knockoutjs render in adminhtmlExecute JavaScript code after swatches are displayed in category viewMagento2 - Customize Order Numbers - Overriding: MagentoSalesSequenceModelSequenceUnable to refresh the page after generating PDF file in order gridError cart message on AjaxSaving a value without triggering aftersave()Add to cart custom templateCall block action using Ajax
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I'm generating a filename via AJAX Jquery. Now I need this filename to be saved. My current process is to call a controller that will do the image saving and it will return a filename/filepath back. Using this new filepath I'm inserting this to a textfield as a value so that when the Add to Cart
function is triggered it will get the generated filepath value and save it as custom option.
But the problem is that the Add to cart
function is being triggered even when the Ajax Jquery hasn't finish it's processing. How can I put the Add to cart
function trigger onhold until the generated filename is returned by the Ajax. I'm thinking of something like a callback function.
Is there a way to achieve this?
jQuery("#product-addtocart-button").on('click', function()
var canvas = jQuery('canvas.canvas');
var canvasImage = canvas[0].toDataURL("image/jpeg", 0.7);
jQuery.ajax(
type: "POST",
dataType: 'json',
url: UPLOADER_URL,
data:
imgBase64: canvasImage
).done(function(response)
last_option.val(response.filename);
console.log("Generated filename", response.filename);
// TRIGGER ADD TO CART FUNCTION HERE
// BUT THE ADD TO CART IS BEING TRIGGERED EVEN IF THE AJAX IS NOT YET FINISH
);
);
magento2 magento2.2 magento2.3 magento-2.0
add a comment |
I'm generating a filename via AJAX Jquery. Now I need this filename to be saved. My current process is to call a controller that will do the image saving and it will return a filename/filepath back. Using this new filepath I'm inserting this to a textfield as a value so that when the Add to Cart
function is triggered it will get the generated filepath value and save it as custom option.
But the problem is that the Add to cart
function is being triggered even when the Ajax Jquery hasn't finish it's processing. How can I put the Add to cart
function trigger onhold until the generated filename is returned by the Ajax. I'm thinking of something like a callback function.
Is there a way to achieve this?
jQuery("#product-addtocart-button").on('click', function()
var canvas = jQuery('canvas.canvas');
var canvasImage = canvas[0].toDataURL("image/jpeg", 0.7);
jQuery.ajax(
type: "POST",
dataType: 'json',
url: UPLOADER_URL,
data:
imgBase64: canvasImage
).done(function(response)
last_option.val(response.filename);
console.log("Generated filename", response.filename);
// TRIGGER ADD TO CART FUNCTION HERE
// BUT THE ADD TO CART IS BEING TRIGGERED EVEN IF THE AJAX IS NOT YET FINISH
);
);
magento2 magento2.2 magento2.3 magento-2.0
What browsers do you support?
– Ben Crook
Jun 3 at 13:52
@BenCrook well I think all browser should be support specially Chrome, Firefox, Safari
– MadzQuestioning
Jun 3 at 14:01
If you don't need to support IE take a look at async and await - developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/…
– Ben Crook
Jun 4 at 9:01
add a comment |
I'm generating a filename via AJAX Jquery. Now I need this filename to be saved. My current process is to call a controller that will do the image saving and it will return a filename/filepath back. Using this new filepath I'm inserting this to a textfield as a value so that when the Add to Cart
function is triggered it will get the generated filepath value and save it as custom option.
But the problem is that the Add to cart
function is being triggered even when the Ajax Jquery hasn't finish it's processing. How can I put the Add to cart
function trigger onhold until the generated filename is returned by the Ajax. I'm thinking of something like a callback function.
Is there a way to achieve this?
jQuery("#product-addtocart-button").on('click', function()
var canvas = jQuery('canvas.canvas');
var canvasImage = canvas[0].toDataURL("image/jpeg", 0.7);
jQuery.ajax(
type: "POST",
dataType: 'json',
url: UPLOADER_URL,
data:
imgBase64: canvasImage
).done(function(response)
last_option.val(response.filename);
console.log("Generated filename", response.filename);
// TRIGGER ADD TO CART FUNCTION HERE
// BUT THE ADD TO CART IS BEING TRIGGERED EVEN IF THE AJAX IS NOT YET FINISH
);
);
magento2 magento2.2 magento2.3 magento-2.0
I'm generating a filename via AJAX Jquery. Now I need this filename to be saved. My current process is to call a controller that will do the image saving and it will return a filename/filepath back. Using this new filepath I'm inserting this to a textfield as a value so that when the Add to Cart
function is triggered it will get the generated filepath value and save it as custom option.
But the problem is that the Add to cart
function is being triggered even when the Ajax Jquery hasn't finish it's processing. How can I put the Add to cart
function trigger onhold until the generated filename is returned by the Ajax. I'm thinking of something like a callback function.
Is there a way to achieve this?
jQuery("#product-addtocart-button").on('click', function()
var canvas = jQuery('canvas.canvas');
var canvasImage = canvas[0].toDataURL("image/jpeg", 0.7);
jQuery.ajax(
type: "POST",
dataType: 'json',
url: UPLOADER_URL,
data:
imgBase64: canvasImage
).done(function(response)
last_option.val(response.filename);
console.log("Generated filename", response.filename);
// TRIGGER ADD TO CART FUNCTION HERE
// BUT THE ADD TO CART IS BEING TRIGGERED EVEN IF THE AJAX IS NOT YET FINISH
);
);
magento2 magento2.2 magento2.3 magento-2.0
magento2 magento2.2 magento2.3 magento-2.0
edited Jun 3 at 14:00
MadzQuestioning
asked Jun 3 at 13:22
MadzQuestioningMadzQuestioning
2619
2619
What browsers do you support?
– Ben Crook
Jun 3 at 13:52
@BenCrook well I think all browser should be support specially Chrome, Firefox, Safari
– MadzQuestioning
Jun 3 at 14:01
If you don't need to support IE take a look at async and await - developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/…
– Ben Crook
Jun 4 at 9:01
add a comment |
What browsers do you support?
– Ben Crook
Jun 3 at 13:52
@BenCrook well I think all browser should be support specially Chrome, Firefox, Safari
– MadzQuestioning
Jun 3 at 14:01
If you don't need to support IE take a look at async and await - developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/…
– Ben Crook
Jun 4 at 9:01
What browsers do you support?
– Ben Crook
Jun 3 at 13:52
What browsers do you support?
– Ben Crook
Jun 3 at 13:52
@BenCrook well I think all browser should be support specially Chrome, Firefox, Safari
– MadzQuestioning
Jun 3 at 14:01
@BenCrook well I think all browser should be support specially Chrome, Firefox, Safari
– MadzQuestioning
Jun 3 at 14:01
If you don't need to support IE take a look at async and await - developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/…
– Ben Crook
Jun 4 at 9:01
If you don't need to support IE take a look at async and await - developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/…
– Ben Crook
Jun 4 at 9:01
add a comment |
1 Answer
1
active
oldest
votes
Try below code.
jQuery("#product-addtocart-button").on('click', function(e)
var self = this;
if (!jQuery(self).hasClass('processing'))
e.preventDefault();
var canvas = jQuery('canvas.canvas');
var canvasImage = canvas[0].toDataURL("image/jpeg", 0.7);
jQuery.ajax(
type: "POST",
dataType: 'json',
beforeSend: function()
jQuery(self).addClass('processing');
,
url: UPLOADER_URL,
data:
imgBase64: canvasImage
).done(function(response)
last_option.val(response.filename);
console.log("Generated filename", response.filename);
e.currentTarget.click();
jQuery(self).removeClass('processing');
);
);
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "479"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f277092%2fpause-add-to-cart-function-after-ajax%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Try below code.
jQuery("#product-addtocart-button").on('click', function(e)
var self = this;
if (!jQuery(self).hasClass('processing'))
e.preventDefault();
var canvas = jQuery('canvas.canvas');
var canvasImage = canvas[0].toDataURL("image/jpeg", 0.7);
jQuery.ajax(
type: "POST",
dataType: 'json',
beforeSend: function()
jQuery(self).addClass('processing');
,
url: UPLOADER_URL,
data:
imgBase64: canvasImage
).done(function(response)
last_option.val(response.filename);
console.log("Generated filename", response.filename);
e.currentTarget.click();
jQuery(self).removeClass('processing');
);
);
add a comment |
Try below code.
jQuery("#product-addtocart-button").on('click', function(e)
var self = this;
if (!jQuery(self).hasClass('processing'))
e.preventDefault();
var canvas = jQuery('canvas.canvas');
var canvasImage = canvas[0].toDataURL("image/jpeg", 0.7);
jQuery.ajax(
type: "POST",
dataType: 'json',
beforeSend: function()
jQuery(self).addClass('processing');
,
url: UPLOADER_URL,
data:
imgBase64: canvasImage
).done(function(response)
last_option.val(response.filename);
console.log("Generated filename", response.filename);
e.currentTarget.click();
jQuery(self).removeClass('processing');
);
);
add a comment |
Try below code.
jQuery("#product-addtocart-button").on('click', function(e)
var self = this;
if (!jQuery(self).hasClass('processing'))
e.preventDefault();
var canvas = jQuery('canvas.canvas');
var canvasImage = canvas[0].toDataURL("image/jpeg", 0.7);
jQuery.ajax(
type: "POST",
dataType: 'json',
beforeSend: function()
jQuery(self).addClass('processing');
,
url: UPLOADER_URL,
data:
imgBase64: canvasImage
).done(function(response)
last_option.val(response.filename);
console.log("Generated filename", response.filename);
e.currentTarget.click();
jQuery(self).removeClass('processing');
);
);
Try below code.
jQuery("#product-addtocart-button").on('click', function(e)
var self = this;
if (!jQuery(self).hasClass('processing'))
e.preventDefault();
var canvas = jQuery('canvas.canvas');
var canvasImage = canvas[0].toDataURL("image/jpeg", 0.7);
jQuery.ajax(
type: "POST",
dataType: 'json',
beforeSend: function()
jQuery(self).addClass('processing');
,
url: UPLOADER_URL,
data:
imgBase64: canvasImage
).done(function(response)
last_option.val(response.filename);
console.log("Generated filename", response.filename);
e.currentTarget.click();
jQuery(self).removeClass('processing');
);
);
edited Jun 4 at 10:44
answered Jun 4 at 4:44
Yash ShahYash Shah
1,081210
1,081210
add a comment |
add a comment |
Thanks for contributing an answer to Magento Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f277092%2fpause-add-to-cart-function-after-ajax%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
What browsers do you support?
– Ben Crook
Jun 3 at 13:52
@BenCrook well I think all browser should be support specially Chrome, Firefox, Safari
– MadzQuestioning
Jun 3 at 14:01
If you don't need to support IE take a look at async and await - developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/…
– Ben Crook
Jun 4 at 9:01