gpt4 book ai didi

php - 需要将数组值从 javascript 传递到 Codeigniter 中的 php Controller

转载 作者:行者123 更新时间:2023-11-28 02:03:57 25 4
gpt4 key购买 nike

我有这个 javascript,可以在数组中存储可用的值:

<script>
$(function(){
$('#preview').click(function(){
var thesum=0;
var rowid=[];
var rowfields=[];
var supplier = document.getElementById("sid").value;
var terms=document.getElementById("terms").value;
var podate=document.getElementById("date1").value;
var reqdate=document.getElementById("date2").value;
var contp=document.getElementById("contactp").value;
var count = ($('#listOfProducts tr').length);
//loop start
var i=0;
grid=$('#listOfProducts input[type="checkbox"]:checked').each(function(){
var $row = $(this).parents('tr');
var $trid =$(this).closest('tr').attr('id');
rowid[i]=$trid;
rowfields.push({itemname: $row.find('td:eq(0)').text(), productname:$row.find('td:eq(1)').text(), productdesc: $row.find('td:eq(2)').text(), unitprice:$row.find('td:eq(3)').text(), quantity:$row.find('td:eq(5) input').val(), amount:$row.find('td:eq(6) input').val()});
i++;
});//each close

var dataString = JSON.stringify(rowfields);
});//preview click close
});//function close
</script>

我需要将行字段数组传递到我的 Controller ,以便我可以开始操作其他函数上的数据。你能帮我解决这个问题吗?

最佳答案

Jquery ajax

$(document).ready(function(){

$('#preview').click(function(){
var thesum=0;
var rowid=[];
var rowfields=[];
var supplier = document.getElementById("sid").value;
var terms=document.getElementById("terms").value;
var podate=document.getElementById("date1").value;
var reqdate=document.getElementById("date2").value;
var contp=document.getElementById("contactp").value;
var count = ($('#listOfProducts tr').length);
//loop start
var i=0;
grid=$('#listOfProducts input[type="checkbox"]:checked').each(function(){
var $row = $(this).parents('tr');
var $trid =$(this).closest('tr').attr('id');
rowid[i]=$trid;
rowfields.push({itemname: $row.find('td:eq(0)').text(), productname:$row.find('td:eq(1)').text(), productdesc: $row.find('td:eq(2)').text(), unitprice:$row.find('td:eq(3)').text(), quantity:$row.find('td:eq(5) input').val(), amount:$row.find('td:eq(6) input').val()});
i++;
});//each close

var dataString = JSON.stringify(rowfields);

//ajax function
//http://api.jquery.com/jQuery.ajax/
$.ajax({
//controller path
url: "/path/to/url",
type: "POST",
dataType: "json",
contentType: "json",
data: dataString
success: function(response){
console.log(response);
},
error: function(response){

console.log(response);
}
}); //ajax close



});//preview click close
});//function close

关于php - 需要将数组值从 javascript 传递到 Codeigniter 中的 php Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18050454/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com