1

I get the following error (which doesn't make any sense to me !!):

TypeError: jImages[i] is undefined          

Code:

$.ajax({ url: 'FilterByToestanden.php',
         data: {aantal: $("#aantToestanden option:selected").text(), tekst: $('#bevat').val()},
         type: 'post',
         success: function(data) {
                      var jImages = JSON.parse(data);
                      alert(jImages[0][0]);
                      var filteredImageList = new Array();
                      for (var i=0, len = data.length; i< len; i++)
                      {
                      filteredImageList[i]=jImages[i][0]+jImages[i][1];
                      }
                      alert(filteredImageList);
                  }
});

2 Answers 2

4

data.length should be jImages.length.

data.length is the length of the JSON string, which is much more than the length of the jImages array. So you were going beyond the end of the array, resulting in trying to access undefined elements.

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

2 Comments

Not sure why it wouldn't work otherwise, but it works now ! thanks
You must be totally clueless if you don't understand the difference, but I added some explanation.
2

data is a string (JSON string), and jImages is a 2d array. In general data.length (string character number) is different from jImages (number of elements inside the array).

you should do something like:

for (var i=0, len = jImages.length; i< len; i++)

Comments

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.