• twitter image
  • facebook image
  • youtube image
  • linkedin image
Language: CMS Made Simple Czech CMS Made Simple France CMS Made Simple Hungary CMS Made Simple Russia CMS Made Simple Netherlands

All times are UTC




Post new topic This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: jQuery Ajax and Chrome
PostPosted: Sun Jan 25, 2015 12:18 pm 
Offline
Power Poster
Power Poster

Joined: Sat Jan 22, 2005 11:19 am
Posts: 463
It's a regular thing to have an ajax form submit items to a cart in the CGEcomm suite... until jQuery changed the rules about how best to submit the request and report on the subsequent results, especially when using Google Chrome.

jQuery now recommends using .done(), .fail() and .always() instead of, as in the past, :success, etc. OK, I can do that EXCEPT with Chrome.

For reasons of its own, even on a successful ajax submission, Chrome failed. Took a bit of research and hair-pulling to come up with the answer. Seems Chrome returns a 302 error response...

In this instance, the #prodlist contains a summary of items, each with its own add-to-cart form.

Here's what I did to compensate:

Code:
// ajax submit add to cart form and update view cart in header
$(document).on('click','#prodlist input:submit',function(e){
    e.preventDefault();
   
    var form = $(this).closest('form');
    var actionUrl = form.attr('action');

    var formData = form.serializeArray();
    formData.push({ name: this.name, value: true });

$.ajax({
type : "POST",
url : actionUrl,
data : formData,
cache : false
})   
   .fail (function(jqXHR) { if ( jqXHR.status !== 302 )
                                  alert("Item could not be added to the cart."); })
   .always(function() {$('.carty li:first').load("{/literal}{cms_selflink href='updated-cart'}&showtemplate=false{literal}");return false; })

});


Top
  Profile  
 
Share On:
Share on Facebook Share on Twitter Share on Google+
Display posts from previous:  Sort by  
Post new topic This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC


Who is online

Users browsing this forum: No registered users


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
HostPapa CMS Made Simple hosting