如何解决REDIPS从函数获取结果作为数组并将其传递给ajax
我正在使用REDIPS库,因此我可以将某些元素拖放到表中。按照库提供的示例,我想将save_content()结果作为数组获取,以便可以将这些值插入数据库中。这是我的方法,但是不起作用。现在,我将输入中的值显示为文本
save_content = function (tbl) {
var query = '',// define query parameter
tbl_start,// table loop starts from tbl_start parameter
tbl_end,// table loop ends on tbl_end parameter
tbl_rows,// number of table rows
cells,// number of cells in the current row
tbl_cell,// reference to the table cell
t,r,c,d; // variables used in for loops
// first sort tables array to it's original order
tables.sort(function (a,b) {
return a.idx - b.idx;
});
// if input parameter is undefined,then method will return content from all tables
if (tbl === undefined) {
tbl_start = 0;
tbl_end = tables.length - 1;
}
// if input parameter is out of range then method will return content from first table
else if (tbl < 0 || tbl > tables.length - 1) {
tbl_start = tbl_end = 0;
}
// else return content from specified table
else {
tbl_start = tbl_end = tbl;
}
// iterate through tables
for (t = tbl_start; t <= tbl_end; t++) {
// define number of table rows
tbl_rows = tables[t].rows.length;
// iterate through each table row
for (r = 0; r < tbl_rows; r++) {
// set the number of cells in the current row
cells = tables[t].rows[r].cells.length;
// iterate through each table cell
for (c = 0; c < cells; c++) {
// set reference to the table cell
tbl_cell = tables[t].rows[r].cells[c];
// if cells isn't empty (no matter is it allowed or denied table cell)
if (tbl_cell.childNodes.length > 0) {
// cell can contain many DIV elements
for (d = 0; d < tbl_cell.childNodes.length; d++) {
// childNodes should be DIVs,not \n childs
if (tbl_cell.childNodes[d].tagName === 'DIV') { // and yes,it should be uppercase
var value = $(tbl_cell).find("input").val();
query += 'p[]=' + tbl_cell.childNodes[d].id //obj id
+ '_' + value + '_' + r + '_' + c + '&';
}
}
}
}
}
}
// cut last '&'
query = query.substring(0,query.length - 1);
// return prepared parameters (if tables are empty,returned value could be empty too)
return query;
};
我想以数组的形式获取查询值,以便无需使用$ _REQUEST即可将值插入数据库中
function save() {
$('#moverCita').modal('toggle');
var content = REDIPS.drag.save_content();
document.getElementById("moverCitaRow").value = content;
}
我将值作为文本输入内部
update.php
if (isset($_POST['submit'])){
if(isset($_POST['moverCitaRow'])){
if (!empty($_POST['moverCitaRow'])) {
$content = $_POST['moverCitaRow'];
$content = @$_REQUEST['p'];
if(is_array($content)) {
foreach ($content as $c) {
list($job_id,$job_bay_id,$row,$col) = explode('_',$c);
try {
update_calendar($job_id,$col);
} catch (Exception $ex) {
$_SESSION["errorMsg"] = $ex->getMessage();
$_SESSION["errorType"] = "danger";
}
}
}
}
else {
echo '<center><strong style="color:red;">Llenar todos los campos
requeridos</strong></center><br>';
}
} }
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。