这是我在这里的第一篇文章,我希望我会遵循所有的规则。我还没有找到任何与我的问题完全吻合的答案。我目前正在开发一个WordPress插件,并用jQuery编写了一个动态表格,可以动态添加,排序和删除行。每一行都有输入字段。现在我想将每行输入字段数据保存为自定义数据库表中的新数据库条目。我已经设法有一个jQuery变量,每个行字段条目用逗号分隔。现在我基本上只需要将这个变量放入数据库查询中,并在那里卡住。也许jQuery变量也是错误的路要走。你们能帮我吗?如何使用jQuery将动态表格行添加到Wordpress数据库
我的jQuery:
jQuery(".save-inv").click(function() {
x = [];
jQuery('table tr:gt(0)').each(function() {
y = '';
jQuery(this).find('td input').each(function() {
y += jQuery(this).val() + ',';
});
if (y != '') {
x.push(jQuery.trim(y))
alert(y);
}
});
});`
警报(Y);返回输入字段的逗号分隔值。在这一点上,我想插入到数据库插入调用,但不知道如何。
我的PHP/HTML(简码WordPress的格式)
$showlist = '<a href="#" class="add-item-btn et-pb-icon" style="font-size: 30px; color: #0c71c3;"></a> Add row<br>';
$showlist .= '<a href="#" class="save-inv et-pb-icon et-waypoint et_pb_animation_top et-animated" style="font-size: 30px; color: #0c71c3;"></a> Save<br>';
//Form Definiton
$showlist .= '<form name="new-inv" method="POST" action="">';
// Header row
$showlist .= '<table id="inv-list" style="width:100%">';
$showlist .= '<thead><tr>';
$showlist .= ' <th></th>';
$showlist .= ' <th>Item name</th>';
$showlist .= ' <th>Description</th>';
$showlist .= ' <th>Category</th> ';
$showlist .= ' <th>Amount</th>';
$showlist .= ' <th>Exp. Date</th>';
$showlist .= ' <th>Alert Date</th>';
$showlist .= ' <th></th>';
$showlist .= '</tr></thead>';
// First item row
$showlist .= '<tbody id="fbody><tr class="item-row">';
$showlist .= ' <td style="padding: 6px 0px 0px 30px"><img src="/wp-content/uploads/2016/05/draggable.png" style="height: 30px;"></td>';
$showlist .= ' <td><input type="text" name="itemname"></td>';
$showlist .= ' <td><input type="text" name="desc"></td>';
$showlist .= ' <td><input type="text" name="cat"></td>';
$showlist .= ' <td><input type="text" name="amount" size="5"></td>';
$showlist .= ' <td><input type="date" class="datepicker" name="expdate"></td>';
$showlist .= ' <td><input type="date" class="datepicker" name="alertdate"></td>';
$showlist .= ' <td><a href="#" style="font-size: 25px; color: #0c71c3;" class="del-item-btn et-pb-icon"></a></td>';
$showlist .= '</tr></tbody>';
$showlist .= '</table></form>';
任何想法?
在此先感谢。
谷歌WP阿贾克斯负载的教程那里 – David