цикл не перебирает все данные ответа в AJAX JQuery - PullRequest
0 голосов
/ 22 сентября 2018

В моей таблице 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

Я использовал оператор 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>

1 Ответ

0 голосов
/ 22 сентября 2018

В этой строке отсутствуют теги <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>");
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...