weixin_33713350 2018-01-05 14:24 采纳率: 0%
浏览 4

发布多个AJAX数据

I'm trying to POST multiple AJAX data to update.php. This is my code at the moment:

$.ajax({  
    url:"update.php",  
    method:"POST",  
    data: $('#update_form').serialize(),   
    beforeSend:function(){  
        $('#update').val("Geupdate!");  
    },  
    success:function(data){  
        $('#update_form')[0].reset();  
        $('#add_data_Modal').modal('hide');  
        $('#employee_table').html(data);  
    }  
}); 

However I also want to sent an ID within the data. This is the form that I'm using.

 <form method="post" id="update_form">
     <label>Notitie:</label>
     <input type="text" name="name" id="' . $row["id"] . '" class="form-control" value='.$row["name"].' width="100%">
     <br />
     <input type="submit" name="update" id="update" value="Opslaan" class="btn btn-success" />
 </form> 

How can I combine data: $('#update_form').serialize() and id="' . $row["id"] . '" together?

I tried a few combinations but I can't find the correct answer. Here is what I've tried:

data: $('#update_form').serialize(), id: <?php echo $row["id"] ?> 
  • 写回答

3条回答 默认 最新

  • weixin_33725126 2018-01-05 14:28
    关注

    You are serializing entire form, which includes your textbox data as well. So, you don't need to explicitly add each element of form.

    The .serialize() method creates a text string in standard URL-encoded notation. It can act on a jQuery object that has selected individual form controls, such as <input>, <textarea>, and <select>: $("input, textarea, select" ).serialize();

    So, whatever element added in form (<input>, <textarea>, and <select>) gets serialized implicitly. So, in case, you wanted to pass additional data along with form, then you can create a hidden field inside your form.

    评论

报告相同问题?

悬赏问题

  • ¥15 java代码写在记事本上后在cmd上运行时无报错但又没生成文件
  • ¥15 关于#python#的问题:在跑ldsc数据整理的时候一直抱这种错误,要么--out识别不了参数,要么--merge-alleles识别不了参数(操作系统-linux)
  • ¥15 PPOCRLabel
  • ¥15 混合键合键合机对准标识
  • ¥100 现在不懂的是如何将当前的相机中的照片,作为纹理贴图,映射到扫描出的模型上
  • ¥15 魔霸ROG7 pro,win11.息屏后会显示黑屏,如图,如何解决?(关键词-重新启动)
  • ¥15 有没有人知道这是哪里出了问题啊?要怎么改呀?
  • ¥200 C++表格文件处理-悬赏
  • ¥15 Windows Server2016本地登录失败
  • ¥15 复合卡卡号轨道写入芯片卡