Interista Posted October 22, 2012 Share Posted October 22, 2012 What is the best way that let me can passing values from JS to PHP .. I have Javascript Shopping Cart , So I need to pass cart items and info to make a query . And I want to keep the cart info even if someone refresh the page . Thanks Quote Link to comment https://forums.phpfreaks.com/topic/269757-passing-values-from-js-to-php/ Share on other sites More sharing options...
Psycho Posted October 22, 2012 Share Posted October 22, 2012 And I want to keep the cart info even if someone refresh the page . Then you should store the cart info in the database or in SESSION data. But, to answer your question directly you can pass variables from the client to the server using Javascript by performing an AJAX request - which I wouldn't suggest for cart info. Quote Link to comment https://forums.phpfreaks.com/topic/269757-passing-values-from-js-to-php/#findComment-1386860 Share on other sites More sharing options...
Interista Posted October 22, 2012 Author Share Posted October 22, 2012 Then you should store the cart info in the database or in SESSION data. But, to answer your question directly you can pass variables from the client to the server using Javascript by performing an AJAX request - which I wouldn't suggest for cart info. Hello , I think it's not good to store the cart info in a database ! so much quires . is that bad in PHP have much quires ? Thank u Quote Link to comment https://forums.phpfreaks.com/topic/269757-passing-values-from-js-to-php/#findComment-1386934 Share on other sites More sharing options...
Psycho Posted October 22, 2012 Share Posted October 22, 2012 Hello , I think it's not good to store the cart info in a database ! so much quires . is that bad in PHP have much quires ? That question cannot be answered. The appropriate number of "queries" (or what I think you mean is how much data should be stored) is completely dependent upon the needs of the application. If the needs of the application requires 5 queries or 500 queries then that is what it takes. To address your specific need, you are wanting to store a user's cart. There are a few different solutions and which one you choose can depend on many factors. You can use sessions, but they will only persist for the user's session (obviously). This is pretty easy to manager. You can store the info in cookies, which will persist across sessions. But, if a user saves a cart it would only be available to them on that same pc. If you want carts to persist across sessions and PCs then you will want to store them in the DB and ties to a user login. There is no right or wrong method - it depends on which one meets your specific needs. Many sites use several methods. Quote Link to comment https://forums.phpfreaks.com/topic/269757-passing-values-from-js-to-php/#findComment-1386989 Share on other sites More sharing options...
Interista Posted October 22, 2012 Author Share Posted October 22, 2012 That question cannot be answered. The appropriate number of "queries" (or what I think you mean is how much data should be stored) is completely dependent upon the needs of the application. If the needs of the application requires 5 queries or 500 queries then that is what it takes. To address your specific need, you are wanting to store a user's cart. There are a few different solutions and which one you choose can depend on many factors. You can use sessions, but they will only persist for the user's session (obviously). This is pretty easy to manager. You can store the info in cookies, which will persist across sessions. But, if a user saves a cart it would only be available to them on that same pc. If you want carts to persist across sessions and PCs then you will want to store them in the DB and ties to a user login. There is no right or wrong method - it depends on which one meets your specific needs. Many sites use several methods. Oh OK , great info that will help me for sure . Thanks for help Quote Link to comment https://forums.phpfreaks.com/topic/269757-passing-values-from-js-to-php/#findComment-1386997 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.