javascript - Ajax Calls Returning Zero in IE/Firefox -
have been working on 2 days , can't figure out causing fail in ie (v11) , firefox. works fine in chrome.
read lot of questions on here covered caching issues multiple ajax calls, particularly ie, don't believe that's issue. code 1 of 2 forms on page. both submitted via jquery, when "submit all" button clicked. disabled first form, though, , second still doesn't function properly.
here's js/ajax code faulty form submission:
$("body").on( "submit", ".update-guest-email", function(event) { event.preventdefault(); var form = $(this); if( form.find('input[name="email"]').val() == "" ) { return; } if (!formchecker(form)){ return; } var datastring = { action : 'update_guest_party', data : form.serializearray() } $.ajax({ cache: false, type: "post", url: ajaxurl, // wp ajax handler. data: datastring, beforesend: function() { form.find('input').prop('disabled', true); }, success: function(response){ //so, if data retrieved, store in response if (response.data >= 1){ form.append('<div class="center confirmed"><span class="dashicons dashicons-yes"></span></div>'); form.removeclass(); } else { form.find('input').prop('disabled', false); $(".errors").html("that's weird; didn't go through. can try again or <a href='mailto:email@gmail.com'>send email</a>.") $('.errors').slidedown(250); } } // close success response. }); // close ajax. }); // end form-submit.
again, functions expected in chrome. firebug shows post data correctly:
action update_guest_party data[0][name] email data[0][value] brundeezy@gmail.com data[1][name] table data[1][value] dw_wedding_mgr_guests data[2][name] id data[2][value] 149
but response '0' (zero). per chrome, response should this:
{"success":true,"data":1}
any appreciated! have on live server, if helpful see in production.
just getting around posting "solution" here and, usual, it's piece of cake.
the issue had nothing browsers. started figured out above, server-side. wordpress requires "nopriv" version of "wp_ajax_" hook function on front-end of website. in other words, reason wasn't working in other browsers, because hadn't signed in admin other chrome. explains why mark saw same issue in chrome, because (obviously) hadn't signed in, either.
below code ended using, in case you'd see example. same function ("bulk_update_address"), need duplicate aforementioned "nopriv" version of hook:
add_action( 'wp_ajax_bulk_update_address', 'bulk_update_address' ); add_action( 'wp_ajax_nopriv_bulk_update_address', 'bulk_update_address' );
i had "nopriv" line there ahead of time...just forgot remove commenting around it. ay-ay-ay. hope saves headache in future!
Comments
Post a Comment