1

I have a 2D array which I want to send to a php page with $.ajax.

This is the code which creates the array:

for (var i = 0; i<rowlen; i++) {
                           if (breakcheck) {
                              break;
                           }
                           for (var j = 0; j<=columnlen; j++) {
                              thtext = columnheads.eq(j).text();
                              current_td = $(newrows[i]).find("td").eq(j);

                              if (current_td.find("input").length >0) {
                                 rowdata[i,thtext] = current_td.find("input").val().trim();
                                 if (rowdata[i,thtext] =='') {
                                    alert("You must complete all fields");
                                    breakcheck = true;
                                    break;
                                 }
                              } else {
                                 rowdata[i,thtext] ='nada';
                              }
                           }//inner loop
                        }//outer loop

The array is filled properly with the nested loops and the I use JSON.stringify to format it. However when the ajax call is made all that is sent is an empty object ([]). What's wrong?

1
  • 1
    I might be wrong, but arr[i,j] is not the way to use multidimension arrays in C-style languages. That would be arr[i][j] Commented Dec 2, 2009 at 8:42

2 Answers 2

2

I might be wrong, but arr[i,j] is not the way to use multidimensional arrays in C-style languages. That would be arr[i][j].

IMHO what arr[i,j] will do is function as comma operator and use only j as an index.

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

Comments

1

OK I solved this by declaring r as an object (var r = {}) instead of declaring it as an array (var r = []). Thanks for the help.

1 Comment

this should be in the original question.

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.