0
    var mydata0 = null;
    $.post('php/ProductionChange.php', function(data) { // This is Where 
    I use an AJAX call into a php file.

      mydata0=data; // This takes the array from the call and puts it 
      //into
     //a variable 
      var pa = JSON.parse(mydata0);             
       var temp = {};


     for (var i = 0; i < data.length-1; i++) {

    var job=pa[i][0];
    var shipdate = pa[i][1];
    var status = pa[i][2];
    var name = pa[i][3];
    var EnclLoc = pa[i][13];
    var Enclsize = pa[i][14];
    var BackPanLoc = pa[i][15];
    var percentCom = pa[i][16];
    var isVis = pa[i][17];
    var png = pa[i][18];
    var WorkC = pa[i][20];
    temp={'bayData': job, shipdate, name, EnclLoc, Enclsize, BackPanLoc, 
    percentCom, isVis, png, WorkC};

    isVacant1.push(temp);

*So I am trying to accomplish is take the object coming out of the pa array***

(0: Array[21] 1: Array[21] 2: Array[21] 3: Array[21] 4: Array[21] 5: Array[21])

which has 6 different arrays inside of it accounting to a total of 816 items. My temp variables successfully grabs onto all the items that I want and isVacant1 successfully gets all of the 6 push inside of it, resulting in isVacant being an array of 6 objects.

However the breaks down once the for loop is over and the error message I am getting is

Uncaught TypeError: Cannot read property '0' of undefined** with a red x next to the first line of my code once the for loop starts **(var job=...)

Please tell me the steps into solving this issue. Thank you for all the help.*

1 Answer 1

1

change

for (var i = 0; i < data.length-1; i++) {

to

for (var i = 0; i <= pa.length; i++) {

You are iterating for length of the data array, but accessing pa. pa is not necessarily the same length as the array called "data".

Sign up to request clarification or add additional context in comments.

1 Comment

lol I literally caught that error as soon as I submitted this question. I am glad for the quick responses. Thanks bud.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.