POST /cart/update.js 404 (Not Found)

Solved
ashwin-ramdas
Excursionist
16 2 2

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);

 

0 Likes
SBD_
Shopify Staff
Shopify Staff
1043 141 183

Are you able to share a link to the code running / shop URL?

0 Likes
ashwin-ramdas
Excursionist
16 2 2

This is an accepted solution.

Hi @SBD_ I actually figured out the issue. The way I was declaring the key in cartUpdates was incorrect. I changed the format to cartUpdates[key] = value instead of cartUpdates = { key: value} and it worked.

nalaka0909
New Member
3 0 0

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

0 Likes
SBD_
Shopify Staff
Shopify Staff
1043 141 183

@nalaka0909 can you link to an example?

0 Likes
nalaka0909
New Member
3 0 0
0 Likes
SBD_
Shopify Staff
Shopify Staff
1043 141 183

I can't replicate on cablebitesanimal.myshopify.com - have you resolved?

0 Likes