1
 var instance = new readers_cls();
 var theID = $('#theID').val();
 var thedata = instance.getReaderNumbers(theID);

 $.each(thedata.data, function(){
 $('#theReader').append('<tr class="readerRow"id="new' + index + '"><td align="center"><input type="text" id="reader' + index + '" name="reader' + index + '" value="' + this.readernumber + '" class="readerName"></td></tr>');
                    index++;
                });

Works fine if I actually have data returned but throws error when returns no data, not sure how to test for the null or not and object on the .each

1
  • What do you want to do if it IS null, add blank rows or no row at all? Commented Apr 23, 2012 at 16:28

1 Answer 1

4

Can't you just do:

if(thedata.data) {
    $.each(thedata.data, function(){
        $('#theReader').append('<tr class="readerRow"id="new' + index + '"><td align="center"><input type="text" id="reader' + index + '" name="reader' + index + '" value="' + this.readernumber + '" class="readerName"></td></tr>');
                index++;
            });
}
Sign up to request clarification or add additional context in comments.

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.