Php 如何使用laravel/ajax获取多个值并存储到数据库
我有以下jQuery代码,我可以通过这个循环获取HTML元素。我想通过AJAX获取数据并将其存储到数据库中。我怎么做Php 如何使用laravel/ajax获取多个值并存储到数据库,php,jquery,ajax,laravel,Php,Jquery,Ajax,Laravel,我有以下jQuery代码,我可以通过这个循环获取HTML元素。我想通过AJAX获取数据并将其存储到数据库中。我怎么做 $('#btnSubmit').on('click', function(){ for(var increment = 0; increment <= pos_inc; increment++) { var text1 = $('#orders' + increment).val(); var text2 = $('#item_quan' + incre
$('#btnSubmit').on('click', function(){
for(var increment = 0; increment <= pos_inc; increment++) {
var text1 = $('#orders' + increment).val();
var text2 = $('#item_quan' + increment).val();
var text3 = $('#price_tot' + increment).val();
}
});
这是你的解决方案
$('#btnSubmit').on('click', function(){
for(var increment = 0; increment <= pos_inc; increment++)
{
var text1 = $('#orders'+increment).val();
var text2 = $('#item_quan'+increment).val();
var text3 = $('#price_tot'+increment).val();
}
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "yoururlhere",
data: "{'text1':'" + text1+ "', 'text2':'" + text2+ "', 'text3':'" + text3+ "'}",
success: function (result) {
//do somthing here
}
});
});
$('btnSubmit')。在('click',function()上{
对于(var increment=0;increment这是您的解决方案
$('#btnSubmit').on('click', function(){
for(var increment = 0; increment <= pos_inc; increment++)
{
var text1 = $('#orders'+increment).val();
var text2 = $('#item_quan'+increment).val();
var text3 = $('#price_tot'+increment).val();
}
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "yoururlhere",
data: "{'text1':'" + text1+ "', 'text2':'" + text2+ "', 'text3':'" + text3+ "'}",
success: function (result) {
//do somthing here
}
});
});
$('btnSubmit')。在('click',function()上{
对于(var increment=0;increment假设它们都是相同的形式,只需$('#yourForm')。serialize()
应该这样做。如果这对您不起作用,那么您需要提供更多有用的信息,例如您的HTML和完整的JS,以及您的服务器在显示表单HTML+控制器函数时希望接收数据的格式!WARE是表单的标题??假设它们都在同一表单中,只需$(“#yourForm”).serialize()
应该可以。如果这对您不起作用,那么您需要提供更多有用的信息,例如您的HTML和完整的JS,以及您的服务器希望在表单HTML+控制器函数中接收数据的格式!WARE是您表单的标题吗??
$('#btnSubmit').on('click', function(){
for(var increment = 0; increment <= pos_inc; increment++)
{
var text1 = $('#orders'+increment).val();
var text2 = $('#item_quan'+increment).val();
var text3 = $('#price_tot'+increment).val();
}
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "yoururlhere",
data: "{'text1':'" + text1+ "', 'text2':'" + text2+ "', 'text3':'" + text3+ "'}",
success: function (result) {
//do somthing here
}
});
});