我正在用jsp创建简单的销售系统。想要将数据添加到数据库中。我不知道检索数据到jsp页面。这就是我如何传递数据功能
var data =“&items =” + JSON.stringify((items));
$.ajax({
type: "POST",url: "sales_add.jsp",dataType: 'JSON',data: data,
数据成功传递,我通过控制台检查。
String [] json = request.getParameterValues(“ items”);这就是我如何将数据检索到jsp页面
for(int x = 0; x < json.length; x++)
{
String item = json[x][0]);
String price = json[x][1]);
String qty = json[x][2]);
String $total = json[x][3]);
此代码不起作用
完整代码
所有销售应添加此表数据。我将发送到sales_add.jsp页面。我这样检查console.log(JSON.stringify(items));我在下面写的完整代码。
function add_product_to_array(item,price,qty,tot)
{
var item = [item,tot];
items.push(item);
console.log(JSON.stringify(items));
}
我通过Console.log检查的表成功显示如下
**[["Chocolate",32,"1",32]]
(index):237 [["Chocolate",32],["Mango",10,10]]**
我以这种方式发送** var data =“&items =” + JSON.stringify((items))到sales.add.php页面
function addProject()
{
var data = "&items=" + JSON.stringify((items));
$.ajax({
type: "POST",success: function (data) {
console.log(_data);
alert("Success");
},error: function (xhr,status,error) {
alert(xhr);
console.log(xhr.responseText);
}
});
}