-2

I have a script that takes the emails from text area an send it with ajax to send.php page, it's work with me when i'm send all of the text area content of if i send line by line, now i'm need to get 10 lines and send it to send.php each time

$(document).ready(function() {
  $("#check").on("click", function(event) {
    event.preventDefault();

    var lines = $('#emails').val().split('\n');

    $.ajax({
      type: 'POST',
      url: 'send.php',
      data: {
        email: lines,
        mail_from: $('#mail_from').val(),
        attach: $('#attach').val(),
        mail_name: $('#mail_name').val(),
        message: $('#message').val(),
        title: $('#title').val()
      },
      success: function(msg) {
        $('#result').append(msg);

      }
    });
  });
});
VLAZ
  • 26,331
  • 9
  • 49
  • 67
  • Possible duplicate of [convert textareas string value to JavaScript array separated by new lines](https://stackoverflow.com/questions/8479053/convert-textareas-string-value-to-javascript-array-separated-by-new-lines) –  Oct 19 '19 at 11:04
  • @RobinSingh The author seems to know how to parse the textarea lines, the question is more about grouping requests by paginating an array – giuseppedeponte Oct 19 '19 at 11:18

1 Answers1

1

You can paginate your lines array by calling the slice method in a loop:

$(document).ready(function() {
  $("#check").on("click", function(event) {
    event.preventDefault();

    var lines = $('#emails').val().split('\n');

    for (var currentPage = 0; lines.length > currentPage * 10; currentPage += 10) {
      var currentLines = lines.slice(currentPage * 10, currentPage * 10 + 10);

      console.log(currentLines.join(', '));
      // Do something...
    }
  });
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<button id="check">Check</button>
<textarea id="emails"></textarea>
giuseppedeponte
  • 2,366
  • 1
  • 9
  • 19