Problems with 414 Request-URI Too Large

GeoffreyGeoffrey Member
in Help edited November 2016
I'm in urgent need of assistance with an error on something I need to deploy next week. I've just set up a complicated product that is basically a very large bundle (customize your own set). I'm looping in data from many other products in one big form and I've run into the 414 URI length limit. I searched the forum for previous references to this problem, and found both of these threads:

https://forum.foxycart.com/discussion/761/ajax-style-form-submission
https://forum.foxycart.com/discussion/8275/414-request-uri-too-large

I have attempted to implement the solution discussed in the first thread, and I've got it to successfully add the bundle product to cart without the 414 error. But the problem I'm running into now is that the sidecart and other json elements on the product page break when I put this solution in place. I understand that this fix was designed for FC 0.6.0, which is ancient now, and I'm using FC 2.0.

Here's the code I'm using for this at the very end of the footer, right before the closing tag:

<script>
jQuery(document).ready(function(){
jQuery('form.foxyshop_product').attr("target", "cart_iframe");
// Fix the form action for users with 3rd party cookies disabled

action = jQuery('form.foxyshop_product').attr('action') + '?' + fc_AddSession();
jQuery('form.foxyshop_product').attr('action', action);

jQuery('#cart_iframe').load(function(){
fc_UpdateCart(FoxyDomain);
jQuery('.foxyshop_cart_link_widget a.foxyshop').click();
});
});
</script>


On page load, the following Javascrip error shows in the console: "Uncaught ReferenceError: fc_AddSession is not defined". Looking at the source I also notice that despite my every attempt to load this script block after all other scripts, it appears that the following script and stylesheet links always load after it as the appended elements before the closing body tag:

<script src="//cdn.foxycart.com/vtdev2/foxycart.jsonp.sidecart.min.1479412300.js"></script>
<link rel="stylesheet" media="screen" href="//cdn.foxycart.com/vtdev2/responsive_styles.1479488741.css">


So it seems that the "fc_AddSession is not defined" error may be breaking the sidecart. Clicking on the view cart link on page only directs to the full page cart. My view cart link widget on this page is also not displaying the json data of the cart items count as it should. Other product pages where I don't load this script have no problems.

Is there a better way to accomplish this in FC 2.0, or at least a way to make this really old fix work in 2.0 without breaking the sidecart and other things? Please let me know as soon as possible. Thanks so much for your help!
Comments
  • fc_adamfc_adam FoxyCart Team
    @Geoffrey,

    Good question. That error does sound like it's getting in the way of Sidecart. Give this version a try instead:
    <script>
    var FC = FC || {};
    FC.onLoad = function () {
    FC.client.on('ready.done', function () {
    jQuery('form.foxyshop_product').attr("target", "cart_iframe");
    // Fix the form action for users with 3rd party cookies disabled

    action = jQuery('form.foxyshop_product').attr('action') + '?' + FC.session.get();
    jQuery('form.foxyshop_product').attr('action', action);

    jQuery('#cart_iframe').load(function(){
    FC.sidecart.show();
    });
    });
    };
    </script>
  • @fc_adam,

    Thanks for the response. I had tried something similar to your version last night, but couldn't get it working. I just switched your version in for the other one on my test page and it also does not work. According to the console log, this version still submits the form with GET. The sidecart loads on submission, but there's nothing in it. And additionally, with this code there is a problem with sidecart refusing to close after it's been opened, where when you try to click away or press continue shopping it bounces back. Perhaps the FC.sidecart.show() is getting stuck in a loop somehow.

    There's no longer any JS errors on page load, but I notice that there are strange errors occuring in jquery.min.js when the sidecart loads. The first error is "Uncaught TypeError: a.getAttribute is not a function(…)", and after that it errors as " Uncaught TypeError: undefined is not a function(…)". These errors do not occur in any other context (on other product pages) when sidecart opens.

    So far, the bundle product has only been successfully added to the cart with the legacy script from 0.6.0, but with the errors I mentioned initially. I'll whisper you a link to my development environment so you can see all this in action.
  • fc_adamfc_adam FoxyCart Team
    @Geoffrey,

    Sorry about that code - I hadn't considered a few aspects of how 2.0 functions, but the page you whispered helped test it in your set up. The following code should work - and you'll want to remove the iFrame from the page, it's now added dynamically as part of the script:
    <script>
    var FC = FC || {};
    FC.onLoad = function () {
    FC.client.on('ready.done', function () {
    jQuery('form.foxyshop_product').attr("target", "cart_iframe").addClass("fc-sidecart--bypass");
    // Fix the form action for users with 3rd party cookies disabled
    action = jQuery('form.foxyshop_product').attr('action') + '?' + FC.session.get();
    jQuery('form.foxyshop_product').attr('action', action);
    appendIframe();
    });
    FC.client.on('sidecart-detach.done', function() {
    appendIframe();
    });
    };
    function appendIframe() {
    $('<iframe id="cart_iframe" name="cart_iframe" width="500px" height="400px" style="display:none;"></iframe>').appendTo('body').load(function() {
    $("#cart_iframe").remove();
    FC.sidecart.show();
    });
    }
    </script>
    The error for Uncaught TypeError: a.getAttribute is not a function(…) still persists, but I believe that is coming from your custom javascript set in the store's header/footer configuration, as it's triggered whenever the cart is rendered.
  • @fc_adam,

    Excellent! This works perfectly. Thank you so much for helping me with this!
  • @fc_adam,

    Actually, still experiencing a problem with this. Everything works fine in Webkit based browsers (Chrome & Safari), but FireFox has issues with the script. In FireFox, the sidecart is opening immediately on page load, and keeps bouncing open after every attempt to close it. Would you please take a look at that and let me know what we can adjust to make this work correctly in Firefox? Thanks!
  • @fc_adam,

    I just checked Internet Explorer 11 as well, and it is having the same problem as Firefox mentioned above.
  • fc_adamfc_adam FoxyCart Team
    @Geoffrey,

    Looks like Firefox and IE trigger the load event for the iFrame even for "about:blank" loading, which isn't helpful! Give this a try:
    <script>
    var FC = FC || {};
    var adding_to_cart = false;
    FC.onLoad = function () {
    FC.client.on('ready.done', function () {
    jQuery('form.foxyshop_product').attr("target", "cart_iframe").addClass("fc-sidecart--bypass");
    // Fix the form action for users with 3rd party cookies disabled
    action = jQuery('form.foxyshop_product').attr('action') + '?' + FC.session.get();
    jQuery('form.foxyshop_product').attr('action', action);
    appendIframe();
    });
    FC.client.on('cart-submit', function() { adding_to_cart = true; });
    FC.client.on('sidecart-detach.done', function() {
    adding_to_cart = false;
    appendIframe();
    });
    };
    function appendIframe() {
    $('<iframe id="cart_iframe" name="cart_iframe" width="500px" height="400px" style="display:none;"></iframe>').appendTo('body').load(function() {
    if (adding_to_cart) {
    $("#cart_iframe").remove();
    FC.sidecart.show();
    }
    });
    }
    </script>
    The code sets a variable when the add to cart is actually happening - and only triggers our loading functionality if that is true.
  • @fc_adam,

    OK! This got everything working, except that FireFox was not loading the sidecart (and going to full cart instead). I made one small adjustment and got FireFox to load the sidecart, so everything works consistently. The adjustment needed was on this part:

    if (adding_to_cart) {
    $("#cart_iframe").remove();
    FC.sidecart.show();
    }


    The FC.sidecart.show() action needed to switch position with the #cart_iframe remove() action, like so:

    if (adding_to_cart) {
    FC.sidecart.show();
    $("#cart_iframe").remove();
    }


    Who knows why Firefox needed it that way, but it's all functional now and that's what matters. Thanks again for your help with this! I deeply appreciate it.
  • fc_adamfc_adam FoxyCart Team
    @Geoffrey,

    Interesting. I'm glad you got it working, although it works for me in that order. Were you seeing some sort of error in the console when it was removing the frame first?
  • @fc_adam,

    I just double checked this, and you are correct. Perhaps it wasn't working initially because of browser cacheing or something. I switched the order back to what you posted, and it works. In any case, it appears to work either way. Sorry for the confusion.
  • fc_adamfc_adam FoxyCart Team
    @Geoffrey,

    No problems - I'm just glad we got it working for you!
Sign In or Register to comment.