将值从localStorage发送到java servlet

时间:2016-12-12 13:17:26

标签: javascript java jquery html5 servlets

我有一个表单,它从用户获取输入并将数组中的所有值作为JSON对象存储到localStorage。在另一个页面上,所有这些对象都显示在它们自己的单独表中。我需要将第二页上显示的所有值(从localStorage中获取)发送到稍后插入数据库的java servlet。这就是我生成表格的方式:

<tbody id = "shoppingcart2"> //html code to where the jquery output is printed
                    </tbody>


   for (var i in cartArray){ //loops through each item in the array and creates its own <tr> with the values.
        outputProduct2 += 
        "<tr>"
        +"<td data-name='name'>"
        + "VM Naam: "
        + cartArray[i].vmnaam + ""
        +"</br>"
        +cartArray[i].name + ""
        +"</br>"
        +"ram:"
        +cartArray[i].ram
        +"</br>"
        +"diskSpace:"
        +cartArray[i].diskSpace
        +"</br>"
        +"cpu:"
        +cartArray[i].cpu
        +"</td>"
        +"<td data-price='Price'>"
        +cartArray[i].price
        +"</td>"
        +"<td data-quantity='Quantity'>"
        +cartArray[i].quantity
        +"<td data-name='subtotal' class='text-center'>"
        +cartArray[i].total
        +"</td>"
        +"</tr>"
    }


$("#shoppingcart2").html(outputProduct2); // jquery is printed to html id shoppingcart2

本地存储看起来如下:

[{"id":2,"vmnaam":"b","name":"Windows Server 2012","price":"25.00","quantity":1,"ram":4,"diskSpace":30,"cpu":1},{"id":3,"vmnaam":"ba","name":"Windows Server 2012","price":"57.50","quantity":1,"ram":6,"diskSpace":70,"cpu":4}]

0 个答案:

没有答案