[SOLVED] How to prevent a second alert bubbling up?

I have a problem that an alert is showing up 2 times and Im trying to prevent it, but nothing is working!?

So how can I prevent the alert from showing a second time in the below code?
I don´t understand why it is showing a second time?

$$(document).on('page:init', '.page[data-name="camera"]', function (e) {
var page = e.detail;

$$( "#sparakamera" ).submit(function( event ) {
		app.preloader.show();
});

app.on('formAjaxSuccess', function (e, data, xhr) {
	
	app.preloader.hide();
				
				if(xhr.response){
				data = JSON.parse(xhr.response);
			  		  
  app.dialog.alert('Produkten är '+pub+' och har fått PRODUKT ID: ' +data +'<br><br>Skriv ner det för produkten du just laddade upp'+arttext+'.','&Aring;TERVINN MERA') 
  		  
				}
			
		 return false;	
});
		
		 event.preventDefault();
		 event.stopImmediatePropagation();
		 return false;	
	    
});

Any input appreciated, thanks.

You assign global handler each time that page loads with app.on

Ok, thanks, so I can´t prevent it I guess. Can I use anything else than app.on('formAjaxSuccess' to check when the ajax.request gets a success callback?

Yes, use DOM event instead

Ok I changed it to $$('form.form-ajax-submit').on('formajax:success', function (e) { and it seams to work, good. Thanks.

1 Like