I’ve got some JS which works in Chrome, but not in FireFox, and I’m too inexperienced in JS to be able to troubleshoot this without some assistance.
I tested it from localhost on my dev machine and from its deployed location (on our internal intranet) … same results in both cases.
In chrome, it does exactly what I expect. It asynchronously catches a JSON object from the API and splashes it for the user.
In FF, it takes the user to the target API URL. No “asynchronisity”.
What tweaks can I do to support FF too??
(fortunately, FF & Chm are the only two I need to code against).
Any and all help will be greatly appreciated.
var submit_map_url = 'blahblah'; // dynamically generated by PHP
$('#mapper_form').submit(function() {
event.preventDefault();
$.ajax({
type:'POST',
url: submit_map_url,
data:$('#mapper_form').serialize(),
success: function(response) {
var response = $.parseJSON(response);
if(response.status == 'failure'){
alert(response.message);
}else{
var doRedirect = true;
$('#splash').fadeIn(800, function() { // fade in
window.setTimeout ( function() { // start a timer for auto redirect
$('#splash').fadeOut(1000, function() { // fade out
if(doRedirect) window.location = redirect_target; // then redirect
}) }
, 4000); //
});
$('#splash').click(function(){ // on click
doRedirect = false; // cancel the redirect request
$(this).fadeOut(700,function() {}); // and fade out
});
$('#countdown').countdown({until: +5, format: 'S'});
} // end IF/ELSE
} // end success:
}); // ajax
return false;
});
Add the
eventparameter to you submit function.$('#mapper_form').submit(function(event) {Chrome has a global event object
window.eventwhen you are in a event handler.