0

我的代码中遗漏了一些东西。我有一个用于百分比值的文本框列表,并且可能有很多输入。

// loop through unknown inputs with different values
<input name="DESIREDPERCENT[<?php echo $recid; ?>]" class="percinputbox" />
// end loop

// attach click event to this element
<span id="updatepercs">Update Percentages</span>

然后我有一个简单的跨度元素来发送所有的输入与类percinputbox

$(document).ready(function(){

 $('#updatepercs').click(function(){
   var allinputs = $("input.percinputbox").serialize();
   console.log(allinputs);  //DESIREDPERCENT%5B73%5D=50.00&DESIREDPERCENT%5B104%5D=50.00    

   $.ajax({
     url:'update.php',
     data:"formId=updatepercentages" + allinputs,
     success:function(response){ alert(response); } 
  }); 

});

我有我的php听力$.ajax

更新.php

<?php
if($_POST['formId'] == 'updatepercentages'){
  foreach( $_REQUEST['DESIREDPERCENT'] as $key ){
    echo $key;
  }
}
?>

到目前为止,我只得到一个输入值。所以我肯定做错了。

我在这里接受更好/优化的方式。我一般使用<form>标签提交表单,但我想知道如何使用jquery.

4

1 回答 1

1

您缺少&介于formId=updatepercentages和之间allinputs

data:"formId=updatepercentages&" + allinputs,

于 2013-03-08T19:33:17.667 回答