Note that there are some explanatory texts on larger screens.

plurals
  1. PO.unbind('submit').submit() works in Chrome/IE but doesn't work in Firefox
    primarykey
    data
    text
    <p>I have the following javascript code using jquery 1.9.1:</p> <pre><code>(function ($) { $(function () { eventTracking(); }); function eventTracking() { $("[data-formtracking]").bind('submit', function (e) { e.preventDefault(); var eventName = $(this).data("formtracking"); rt.trackEvent(eventName); $(this).unbind('submit').submit(); }); }})(jQuery); </code></pre> <p>Now, when I submit the form, it should make an update to a database, and then follow the action that is on the form, and basically redirect us to the other page.</p> <p>In Chrome/IE the rt.trackEvent successfully fires and I get redirected to the other site. In Firefox, I get redirected to the other site, but no database entry. </p> <p>If I add console.log between each statement, I can see that it is hits all of the log statements.</p> <p>So at this point....I'm baffled. I've tried switching from bind to on/off. I've tried: $('input[type=submit]', this).click() based on a passing comment on another stackoverflow page.</p> <p>A few notes: * rt is in an external file. I've checked and it does exist * If I remove the unbind.submit, then the rt.trackEvent works correctly, except the page doesn't redirect (obviously). * I've change the unbind.submit() to other variations, but then I have to click the button twice before it submits.</p> <p>Thoughts?</p> <p><strong>Updated</strong></p> <p>The reason for the e.preventDefault() and later submission is that the form submission was happening too quickly. The page would redirect before rt.trackEvent would work properly. So I needed to slow the method down by adding a setTimeout($(this).unbind('submit').submit(), 2000); </p> <p>I removed this to simplify the code, but in hindset it is pretty essential for the working of the code.</p> <p><strong>Updated 2</strong> Here is the json that is being called:</p> <pre><code> options = $.extend({ success: $.noop, error: $.noop, urlBuilder: getNoCookieRequestURL, eventName: null }, options); options.url = options.urlBuilder(options.url, options.siteId, options.eventName); $.getJSON(options.url, function (jsonp) { options.success(jsonp); }).fail(function () { options.error(); }); </code></pre> <p><strong>Updated 3</strong></p> <p>Change getJson to:</p> <pre><code> options = $.extend({ success: $.noop, error: $.noop, urlBuilder: getNoCookieRequestURL, eventName: null }, options); options.url = options.urlBuilder(options.url, options.siteId, options.eventName); $.ajax({ url: options.url, dataType: 'json', async: false, success: function (jsonp) { options.success(jsonp); }, error: function() { options.error(); } }); </code></pre> <p>I still seem to be having the speed issue. Code works when I step through it in Chrome, but database doesn't get updated properly when I just run it.</p>
    singulars
    1. This table or related slice is empty.
    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.
    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