weixin_33696822 2015-12-02 04:30 采纳率: 0%
浏览 44

AJAX传递表单数据

I am trying to figure out why this is not working. Here is the sub-set of my form that looks like this:

   <input type="hidden" id="gift_id3" name="giver3gift_id" value="925"></td>
   <tr id="tr3">
       <td>
            <select class="type" id="type3" name="giver3paymenttype_val">
             <option value="1" SELECTED>Check</option>
             <option value="2">Cash</option>
             <option value="3">ACH</option>
             <option value="4">In Kind Donation</option>
          </select>
       </td>
       <td><input type="text" class="refnum" id="refnum3" name="giver3ref_num" value="2147483647"></td>
       <td><input type="text" class="amount" id="amount3" name="giver3amount" value="25.00" onBlur="this.value=formatCurrency(this.value)"></td>
       <td>
            <select class="type" id="type3" name="giver3taracct_val">
             <option value="1" SELECTED>General Fund</option>
             <option value="2">Building Fund</option>
             <option value="3">Missions Fund</option>
          </select>
       </td>
       <td><input type="checkbox" id="void3" name="giver3void">
   </tr>

Here is my AJAX:

var $inputs = $("#dialog-editgiving :input");
var parameters = [];                  

$inputs.each(function() {
   parameters[this.name] = $(this).val();
});

$.ajax({
   url : "./scripts/form_process/update_giving.php",
   type: "POST",
   data : {parameters:parameters},
   success: function(data, textStatus, jqXHR)
         {
           alert(data);
         },
   error: function(jqXHR, textStatus, errorThrown)
         {
           alert(errorThrown);
          }
});

Here is my update_giving.php file

<?php

foreach ($_POST as $key => $value) {
 echo "Field ".htmlspecialchars($key)." is ".htmlspecialchars($value)."<br>";
}

?>

When I look through the $inputs array, I get the the values that are submitted in the form. Then it is handed off to the "./scripts/form_process/update_giving.php" script, I get nothing in the POST object.

Do I have something incorrect in my AJAX request?

  • 写回答

4条回答 默认 最新

  • weixin_33698043 2015-12-02 04:39
    关注

    instead of this code

    var $inputs = $("#dialog-editgiving :input");
    var parameters = [];                  
    
    $inputs.each(function() {
       parameters[this.name] = $(this).val();
    });
    

    use

    var paramerter = $( '#dialog-editgiving' ).serialize();
    

    for fetching all input from the form..

    and fetch data in update_giving.php file as yoy fetch in normal php function for example

    $_POST['giver3taracct_val'];
    

    i hope this code will help you.

    评论

报告相同问题?

悬赏问题

  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler