Note that there are some explanatory texts on larger screens.

plurals
  1. POcatch variable in ajax success function to stop submit form
    text
    copied!<p>I have a problem within this code. I want to choose whether I will submit the form or not based on the outcome off the ajaxcall.</p> <p>If I hardcode it with return false; It stops going to the paypal site. That's why I want it to depend on a variable set in the ajax succes function.</p> <p>It is probably lost in the callback, so that's why I ask for help.</p> <p>This is the code:</p> <pre><code>$("#img_download").click(function(e){ $("#main_content").find('span').not('#loading').remove(); loading.fadeIn(1000); $("#main_content").load("../../../includes/snip.php #betaalbox", function(){ var invoerGebruikersnaam = $("#gebruikersnaam"); var invoerEmail = $("#email"); loading.hide(); if($("#uitloggentaxibel").size()!=0){ //alert('we zijn ingelogd'); $('#idgebruikerbox').hide(); ingelogd=1; }else{ invoerEmail.focus(); //alert('we zijn niet ingelogd'); } $('form#paypalio').submit(function(){ if(invoerGebruikersnaam.attr("value") &amp;&amp; invoerEmail.attr("value")){ alert('is gecheckt, check ook op geldig emailadres'); //check ook voor een geldig emailadres //OK, dan... //vergelijk met db gegevens gebruikersnaam = invoerGebruikersnaam.attr("value"); email = invoerEmail.attr("value"); $.ajax({ url: "/includes/pdt_paypal.php", data: ({gebruikersnaam: gebruikersnaam, actie: "idgebruikercheck", email: email}), cache: false, type: "POST", dataType: "json", timeout: 5000, success: function(data,textStatus){ //$('#main_content').html(data.responseText); //sla geretourneerde gegevens bij gebruiker op identificatie=data.check; if(identificatie=="ok"){ customstring=email; $('.bericht.idgebruikerfout').html('identificatie was ok').show(); }else{ $('.bericht.idgebruikerfout').html('identificatie heeft gefaald').show(); annuleerPayPal="ok"; } }//EINDE success ,error: function(XMLHttpRequest, textStatus, errorThrown) { if(textStatus == 'timeout') { //doe iets }else if (textStatus == 'error'){ //doe iets } }//EINDE error });//EINDE ajax //ZOJA, dan... }else{ $('.bericht.idgebruikerfout').html(idfout2).show(); return false; } if(annuleerPayPal=="ok"){return false;} //return false; });//EINDE submit });//EINDE load }); </code></pre> <p><strong>EDIT BECAUSE</strong></p> <p>I solved it by removing the logic off setting a variable, because it get's lost. My best guess is that the different callbacks return to a different context.</p> <p>Anyway, by being a bit more direct, by evaluating an if/else statement block within one context(callback), I simply Instruct to submit the form. $('form').submit();</p> <p><strong>solved</strong></p> <p>thanks, Richard</p>
 

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