Which one would you would go for:
Click on the Item, javascript开发者_开发问答 will get the ID from clicked item and then validate the ID via ajax (php/database). If the ID is correct and then save the ID in the session cart.
Click on the Item, javascript will get the ID from clicked item and then save the ID in the session (PHP) via ajax without ID validation. When user clicked on the proceed button, it will then validate all the ID's from the session..
Your method?
If I understand you correctly, you are asking whether the ID's in the shopping basket (i.e session) are validated one-by-one as the user adds them, or at checkout.
Am not sure that it really matters. Perhaps by doing validation at checkout you can do it all in one database call, but apart from this small consideration I can't think of a big reason to do one or the other.
I'd go with (3):
When clicking the item, try adding it to the session/cart and silently fail or display an error if the ID was invalid.
If I understand you correctly someone tampering with the data or you deleting an article is the only way where an id could be invalid anyway.
精彩评论