I am trying to run $.ajax from inside of a function, but it does not seem to work. I get the error "POSTmyshopifysite.com /cart/update.js 404 (Not Found)" Here is my code
(function($) { function add_security_deposit(deposit_quantity, variant_id, qtyInTheCart, cartUpdates, cartItems, container_size) { cartUpdates = { variant_id : deposit_quantity } var params = { type: 'POST', url: '/cart/update.js', data: { updates: cartUpdates }, dataType: 'json', success: function() { window.location.href = '/cart'; } } $.ajax(params);
}
if ({{deposit_quantity_4}}>0) {
add_security_deposit({{deposit_quantity_4}}, {{variant_id_4}}, qtyInTheCart_4, cartUpdates_4, cartItems, '4oz stop');
}
return;
}) (jQuery);
Interestingly, the ajax call works when I don't call it from within a function. For example, the below works. But I want to call ajax from within a function because I'll have to call that function several times. Why am I not able to call ajax within a nested function?
(function($) {
cartUpdates_4 = { {{ variant_id_4 }}: {{deposit_quantity_4}} } var params_4 = { type: 'POST', url: '/cart/update.js', data: { updates: cartUpdates_4 }, dataType: 'json', success: function() { window.location.href = '/cart'; } } $.ajax(params_4);
return;
}) (jQuery);
Solved! Go to the solution
hey i have the same problem on my add to cart button. When ever i try to add to cart my product and then i go to the add to cart icon i see this
Not Found
The requested URL /temp_liquid/cablebitesanimal-myshopify-com-cart.liquid was not found on this server.
please help me i cant start my shop because of this problem
and yes i have change my name for my store 2 times i think that is the reason but i have no clue how to fix it
User | Count |
---|---|
12 | |
12 | |
10 | |
7 | |
6 |