简体   繁体   English

从php中的jquery检索数组值

[英]retrieve array value from jquery in php

I am using a jquery change event using a slider to present to a user the amount of inputs that they select from the slider. 我正在使用一个jquery更改事件,使用滑块向用户显示他们从滑块中选择的输入量。 I am struggling to find a way to process these results in php and insert into mysql. 我正在努力找到一种方法来处理这些结果在PHP中并插入到mysql中。 I would be grateful if someone could start me off with this. 如果有人能让我这么做,我将不胜感激。 Thank you 谢谢

for(var i = 0;i < $(this).val();i++) {
$("#boxamount").append('<div data-role="fieldcontain"><label for="boxamount" class="ui-input-text">Enter box ' + (i + 1) + ' number:</label><input type="text" name="boxamount['+i+']" id="boxamount['+i+']" class="boxamount ui-input-text ui-body-null ui-corner-all ui-shadow-inset ui-body-c" /></div>')
}

Well, you could loop over the text boxes, store the values in an object and submit them via an ajax request. 好吧,你可以遍历文本框,将值存储在一个对象中,并通过ajax请求提交它们。 Here's some rough code below. 这是下面的一些粗略代码。

var data = {}; 
$('input[name^="boxamount"]').each(function(){
    data[ $(this).attr('id') ] = $(this).val();  
}); 

Then perform an ajax request. 然后执行ajax请求。

$.ajax({
   type: "POST",
   url: "yourServerScript.php",
   data: data, 
   success: function(msg){
     alert( "Data Saved: " + msg );
   }
 });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM