开发者

setting a session for a checkbox without $_POST (AJAX?)

I am working on an ecommerce solution using opencart, that has a bunch of checkboxes in order to batch update.

This field is a custom field and what I'm looking to do, is when the user selects these and then continues shopping when they return, they are checked.

I have the following code:

<input class="something" type="checkbox" value="£开发者_如何学Python11.75" name="vat[]">
<input class="something" type="checkbox" value="£25.75" name="vat[]">

So when the first one is checked, it needs to be added to the session.

How woukd I do this? Could I use javascript/jquery to do an Ajax post to a script that would set the session for each checkbox?

Thanks


You'd use something like this

$('input.something').click(function() {
   $.ajax({
      url: 'http://...',
      data: {'checkbox' : this.value }
      ...
   });
});

however, you should ask yourself if it's really required that every change in a checkbox be immediately sent to the server. Does checking off £11.75 mean that other tabs/windows on the site must be aware of that change? If it's just to update a shopping cart, then wait until the user's done making their changes, THEN send the current values to the server in-bulk. Otherwise you're just using up bandwidth and server resources for no good reason.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜