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;








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
);

);









share|improve this question
























  • 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

















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
);

);









share|improve this question
























  • 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













0












0








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
);

);









share|improve this question
















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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

















  • 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










1 Answer
1






active

oldest

votes


















0














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');
);

);





share|improve this answer

























    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
    );



    );













    draft saved

    draft discarded


















    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









    0














    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');
    );

    );





    share|improve this answer





























      0














      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');
      );

      );





      share|improve this answer



























        0












        0








        0







        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');
        );

        );





        share|improve this answer















        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');
        );

        );






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Jun 4 at 10:44

























        answered Jun 4 at 4:44









        Yash ShahYash Shah

        1,081210




        1,081210



























            draft saved

            draft discarded
















































            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.




            draft saved


            draft discarded














            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





















































            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







            Popular posts from this blog

            Category:9 (number) SubcategoriesMedia in category "9 (number)"Navigation menuUpload mediaGND ID: 4485639-8Library of Congress authority ID: sh85091979ReasonatorScholiaStatistics

            Circuit construction for execution of conditional statements using least significant bitHow are two different registers being used as “control”?How exactly is the stated composite state of the two registers being produced using the $R_zz$ controlled rotations?Efficiently performing controlled rotations in HHLWould this quantum algorithm implementation work?How to prepare a superposed states of odd integers from $1$ to $sqrtN$?Why is this implementation of the order finding algorithm not working?Circuit construction for Hamiltonian simulationHow can I invert the least significant bit of a certain term of a superposed state?Implementing an oracleImplementing a controlled sum operation

            Magento 2 “No Payment Methods” in Admin New OrderHow to integrate Paypal Express Checkout with the Magento APIMagento 1.5 - Sales > Order > edit order and shipping methods disappearAuto Invoice Check/Money Order Payment methodAdd more simple payment methods?Shipping methods not showingWhat should I do to change payment methods if changing the configuration has no effects?1.9 - No Payment Methods showing upMy Payment Methods not Showing for downloadable/virtual product when checkout?Magento2 API to access internal payment methodHow to call an existing payment methods in the registration form?