![](/img/trans.png)
[英]How to loop through an array in an Ajax data response with Jquery?
[英]for loop not iterating through the entire response data in ajax jquery
我的表中有 9 列choosen_emails_1
、 choosen_emails_2
、 choosen_emails_3
、 booking_address
、 booking_number
、 booking_message
、 booking_date
、 request_date
和user_email
for
循环迭代并打印除user_email
和booking_number
之外的user_email
booking_number
我在控制器类中使用了Println
语句来检查查询选择器是否选择了我的表中的所有列,并打印了所有 9 列
所以后端代码没有问题。 任何人都可以告诉我这个 jquery 中是否有任何问题! 代码
data = ""; myfunction = function() { $('.tablecontainer').show(); load(); } load = function() { $.ajax({ url: 'updatedservicerequests', type: 'POST', data: {}, // function to get the value from jsp page and send it to mapped class function// success: function(response) { // if the backend process is success then the function will run by getting the response as its parameter// alert(response.message); data = response.data; alert(response.data); $('.tr').remove(); alert(response.data); $(function() { for (i = 0; i < response.data.length; i++) { $("#table").append(response.data[i].user_email + "'>" + response.data[i].booking_number + " </td> <td> " + response.data[i].booking_address + " </td> <td> " + response.data[i].booking_date + " </td> <td> " + response.data[i].booking_message + " </td> <td> " + response.data[i].request_date + " </td> <td> " + response.data[i].chosen_emails_1 + " </td> <td> " + response.data[i].chosen_emails_2 + " </td> <td> " + response.data[i].chosen_emails_3 + "</br>"); } //to prevent (contact-submit) button from submitting form data since submit button has default action of submitting form $(document).ready(function() { $('#contact-submit').click(function(e) { return false; }); }); } }); }, error: function(response) { alert("unable to pull up any service request"); } });
<button onclick="myfunction();">Go</button> <div class="tablecontainer" style="display: none;"> <table id="table" border=1> <tr> <th> booking_address </th> <th> booking_date </th> <th> booking_message </th> <th>request date and time </th> <th> requested_tech_1 </th> <th> requested_tech_2 </th> <th>requested_tech_3 </th> <th>xyz</th> <th>abc</th> </tr> </table> </div>
该行缺少这两个字段周围的<td>
标记,以及整行周围的<tr>
标记。
$("#table").append(response.data[i].user_email + "'>" + response.data[i].booking_number + " </td> <td> " + response.data[i].booking_address + " </td> <td> " + response.data[i].booking_date + " </td> <td> " + response.data[i].booking_message + " </td> <td> " + response.data[i].request_date + " </td> <td> " + response.data[i].chosen_emails_1 + " </td> <td> " + response.data[i].chosen_emails_2 + " </td> <td> " + response.data[i].chosen_emails_3 + "</br>");
你也不应该在那里有</br>
- 这甚至不是一个有效的标签,它当然不属于<table>
。
正确的代码是:
$("#table").append("<tr> <td> " + response.data[i].user_email + " </td> <td> " + response.data[i].booking_number + " </td> <td> " + response.data[i].booking_address + " </td> <td> " + response.data[i].booking_date + " </td> <td> " + response.data[i].booking_message + " </td> <td> " + response.data[i].request_date + " </td> <td> " + response.data[i].chosen_emails_1 + " </td> <td> " + response.data[i].chosen_emails_2 + " </td> <td> " + response.data[i].chosen_emails_3 + "</td> </tr>");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.