ajax:如何发送每种形式的身体并禁用相应的按钮

问题描述 投票:0回答:1

如何通过ajax发送每种形式的身体?

如何根据返回请求ajax禁用相应的按钮。

<script> $(document).ready(function () { var formDates = $('form').serializeArray() //I want to send each form of body $.each(formDates, function () { //This part I don't know how must be $.ajax({ type: "POST", url: "file.php", data: formDates, success: function (data) { $("#dates").html(data) //Return a variable called 'condition' if (condition == true) { $("addFavs").prop("disabled", true); //I want disable the button which correspond to the form I send } if (condition == false) { $("removeFavs").prop("disabled", true); //I want disable the button which correspond to the form I send } } //End of success de AJAX }) //End of ajax request }) //End of each //}) }) </script> </head> <body> <form id="form1"> <input type="text" value="date1" name="name1" /> <input type="text" value="date2" name="name2" /> <input type="text" value="date3" name="name3" /> <button type="button" class="addFavs form-button">Add</button> <button type="button" class="removeFavs form-button">Remove</button> </form> <form id="form2"> <input type="text" value="date4" name="name1" /> <input type="text" value="date5" name="name2" /> <input type="text" value="date6" name="name3" /> <button type="button" class="addFavs form-button">Add</button> <button type="button" class="removeFavs form-button">Remove</button> </form> <span id="dates"></span> </body>
  1. trone,我已经在您的脚本中进行了以下更改:
获取所有表单,而是所有表单数据。
提交当前表单元素的当前表格参考。

$(document).ready(function() { var form = $('form'); //Getting all forms $.each(form, function(i, formC) { //This part I dont know how must be var formDates = $(formC).serializeArray(); $.ajax({ type: "POST", url: "file.php", data: formDates, success: function(data) { $("#dates").html(data) //Return a variable called 'condition' if (condition == true) { $(formC).find("addFavs").prop("disabled", true); //I want disable the button wich correspond to the form I send } if (condition == false) { $(formC).find("removeFavs").prop("disabled", true); //I want disable the button wich correspond to the form I send } } //End of success de AJAX });//End of ajax request });
javascript jquery ajax post
1个回答
0
投票

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.