【问题标题】:How to send a data array whilst using jquery form plugin?如何在使用 jquery 表单插件时发送数据数组?
【发布时间】:2014-11-17 17:56:38
【问题描述】:

我正在尝试将数据数组发送到执行某些处理任务(例如插入等)的 php 处理器页面...但是,似乎没有发送数据并且 php 抛出此错误

错误:

Notice: Undefined index: reci in C:\Users\YASIN\Desktop\SERVER\htdocs\drawer_mess_page_process.php on line 67 Warning: array_map(): Argument #2 should be an array in C:\Users\YASIN\Desktop\SERVER\htdocs\drawer_mess_page_process.php on line 67

发送数据的jquery代码:

    $(document).ready(function () {
        var reci_arr = [];
        var i = 0;
        $('.recipient_tab').each(function(){
             var a = $(this).attr('data-recipient');
             reci_arr[i++] = $(this).attr('data-recipient');
        });
        var time=new Date().getTime();
        var options = {  
                        url:'processor.php',
                        type:'POST', 
                        resetForm:true,
                        data:{reci:reci_arr,time:time},// the data reci is not being sent other data is being sent
                        beforeSend:function(html){
                                                 },

                        success:function(html) {
                                                 //doing stuffs which works 
                                               },
                      };  

        $('#hide_selector_mess_draw').change(function() 
        {
          $('#add_photo_mess_draw').ajaxForm(options).submit(); 
        });
    });

处理数据的php代码

function clean_arr ($a)
{
  $db = mysqli_connect("localhost", "root", "stark1998" ,"users") or die("Could not connect database");
  return mysqli_real_escape_string($db, $a);
}
$reci= array_map('clean_arr', $_POST['reci']);//to_acc

【问题讨论】:

  • 在 js 中你发送两个参数,键为 reci 和 time,在服务器端你问 vor $_POST['recipie'] - 输入错误,缺少代码?
  • @axel.michel 不,这是一个错字,但我认为 .each 函数没有被调用

标签: php jquery arrays forms plugins


【解决方案1】:

在发送数据数组时,旧的 jQuery Form pluign 中有一个 BUG。下载最新版本(atm 3.51.0-2014.06.20)。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-09-26
    • 2021-10-20
    • 2015-08-21
    • 2012-03-19
    • 1970-01-01
    相关资源
    最近更新 更多