Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to use jquery callback functions in if statement?
    primarykey
    data
    text
    <p>I have a function whinch performs something and it works great. Now i want to add a bootstrap modal and execute the same code when modal closes. But my problem is that i have to check for user status. Is there a way how to execute this code and not to copy everything twice?</p> <pre><code>if(USERTYPE == 0) { $("#fastRegisterModal").modal('show'); $("#fastRegisterModal").on('hidden', function() { //Code for registration and upload code } } else { //upload code } </code></pre> <p>I want to include this into multiple jquery function (mostly .live functions) and i don't want to move "upload code" into normal js function (I got the .js file writen as it is and i don't want to change 70% of the file)</p> <p>Is this even possible in this or any other way?</p> <h2>EDITED</h2> <p>Here is some more code:</p> <pre><code>$('.someAction').live('click', function(event) { // Init section var data1 = $(".getData1").val(); var data2 = $(".getData2").val(); // I want to add this modal check before exsisting code if(USERTYPE == 0) { $("#fastRegisterModal").modal('show').on('hidden', function() { var email = $(".getModalEmail").val(); var pass = $(".getModalPass").val(); $.ajax({ url: "actions/fastRegister", type: 'POST', data: {email: email, pass: pass}, success: function(data) { if (data.success == 1) { // continue with existing block of code } } }); }); } // Existing block of code $.ajax({ url: "actions/someAction", type: 'POST', data: {data1: data1, data2: data2}, success: function(data) { if (data != '') { // show success } } }); }); </code></pre> <p>I hope this explaings my situation bether :)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload