0

I'm doing a script that send data to a particular PHP page and getting the result, after that the jQuery will check the result and distribute it.

The data is sent without any problem, and it is distributed fine. However whenever i want to print the distributed data in their rows I'm getting all the values as Undefined, and this is the code that i tried:

 $(document).ready(function () {
     $('textarea').css("resize", "none");    
     var recource = $('#recource').val().split("\n");
     var socks = $('#socks').val().split("\n");    
     $("button").click(function () {    
         for (i = 0; i < recource.length; i++) {    
             $.ajax({
                 type: 'POST',
                 url: 'ajax.php',
                 data: 'email=' + recource[i],
                 success: function (data) {
                     if (data == "Hey, OK") {
                         $('#live').append('<br />' + recource[i]);
                     } else {
                         $('#die').append('<br />' + recource[i]);
                     }
                 }    
             });  
         }
     });
 });
Alex
  • 8,461
  • 6
  • 37
  • 49
SniperCoder
  • 823
  • 2
  • 11
  • 23
  • your return value is `data` not `recource` you should manipulate `data`. do console.log(data) to see what it looks like and there you can manipulate it – guradio Nov 21 '15 at 02:37
  • Please, take a look at [How to return the response from an asynchronous call?](http://stackoverflow.com/questions/14220321/how-to-return-the-response-from-an-asynchronous-call): _[...] **sending the request (or rather receiving the response) is taken out of the normal execution flow** [...]_ . It might help you understand your problem. – FirstOne Nov 21 '15 at 02:46
  • I'm receiving my response successfully, however the data in the array is not displayed. – SniperCoder Nov 21 '15 at 02:54
  • what did you get on console.log(data) – guradio Nov 21 '15 at 02:58
  • I'm getting that the value of (i) is always 3 it does not start from 0. also who did this question duplicated fix the code! i did not find any answer – SniperCoder Nov 21 '15 at 03:11

0 Answers0