找到你要的答案

Q:Refreshing shoping card with JavaScript

Q:清爽的购物卡使用JavaScript

I have the following problem:

I am new to sessions in Java and JavaScript. I have one iframe for my shoping card, and one for the content of my wbeshop. I have articles that you can put in the shoping card as a part of a session.

How can make script that automatically sees that I put a new article to the shoping card in my shoping card iframe?

我有以下问题:

我是新来的在java和javascript的会议。我有我的购物卡一个iframe,和一个我wbeshop内容。我的文章可以作为会话的一部分放在购物卡。

怎样可以让脚本自动认为我把一个新的物品的购物卡在我的购物卡iframe?

answer1: 回答1:

I think that you will be attach the problem from other point of view. If I were you, I will create the shopping cart outside iframe (not use iframes) then you will need:

  1. When user click on "add product to cart": You send product data to the server using javascript with ajax call.
  2. The server will add the product to the session, database, .... (your storage) and return you and ajax status (ok or error). If all will be ok then you update your shopping cart on the browser.

I think this is a better approach.

Using frames Anyway, if you want to use iframes, you should use postMessage html5 api to the iframe send a notification to parent page and then parent page will update the shopping cart on the browser. This method is not 100% available on some browsers like IE: http://caniuse.com/#search=postmessage

我认为你会从另一个角度来看待这个问题。如果我是你,我会创建购物车外iframe(不使用iframe)然后你需要:

  1. When user click on "add product to cart": You send product data to the server using javascript with ajax call.
  2. The server will add the product to the session, database, .... (your storage) and return you and ajax status (ok or error). If all will be ok then you update your shopping cart on the browser.

我认为这是一个更好的方法。

Using frames Anyway, if you want to use iframes, you should use postMessage html5 api to the iframe send a notification to parent page and then parent page will update the shopping cart on the browser. This method is not 100% available on some browsers like IE: http://caniuse.com/#search=postmessage

java  javascript  session  servlets