douyoupingji7238 2015-03-26 12:37
浏览 58
已采纳

jQuery创建并将数组发布到PHP脚本

My experience with jQuery is very limited, and im on a very steep learning cure.

I have a dynamic form which is generated based on main and sub menu, placing marker points in each row which has an inputfield, I have managed to create a loop which looks for all the marker points and return the field_name and the field_value of any input field.

$('td[edit="1"]').each(function(i, el) {
    field_name = $(el).attr('fieldname');
    field_val = $('#'+field_name).val();

    alert(field_name + " = " + field_val);
});

What I am having trouble with now, is converting this in to an array or JSON and pushing it to a PHP file which can then pick up the results.

Here is an example of how I currently submit a forms data to a PHP file, however is not dynamic as I have to specify which fields and values I want to send.

$.ajax({
    type: "POST",
    url: "form.php",
    data: {
        title : title,
        age : age

    }).done(function(data) {
        results = $(data).find('data').html();

    }).fail(function() {
        alert("error");
    }
);
  • 写回答

2条回答 默认 最新

  • dragon87836215 2015-03-26 12:42
    关注

    As data you can user Jquery on the form to create an array of all the data: https://api.jquery.com/serializeArray/

        $.ajax({
            type: "POST",
            url: "form.php",
                data: $('#idOfForm').serializeArray()
        }).done(function(data) {
            results = $(data).find('data').html();
        }).fail(function() {
            alert("error");
        });
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 python:excel数据写入多个对应word文档
  • ¥60 全一数分解素因子和素数循环节位数
  • ¥15 ffmpeg如何安装到虚拟环境
  • ¥188 寻找能做王者评分提取的
  • ¥15 matlab用simulink求解一个二阶微分方程,要求截图
  • ¥30 乘子法解约束最优化问题的matlab代码文件,最好有matlab代码文件
  • ¥15 写论文,需要数据支撑
  • ¥15 identifier of an instance of 类 was altered from xx to xx错误
  • ¥100 反编译微信小游戏求指导
  • ¥15 docker模式webrtc-streamer 无法播放公网rtsp