0

I have write a code and getting the values via jQuery and Ajax using the following code, the data comes fine but i could not populate the rows in my table. the looping is not work.

This is my table code in html

<div class="panel-body">
        <table class="table">
            <thead>
            <tr>
                <th>#</th>
                <th>Hospital Details</th>
                <th>Requested Product</th>
                <th>Units</th>
                <th>Patient Details</th>
                <th>Interval</th>
                <th>Requester</th>
            </tr>
            </thead>
            <tbody id="result">

            </tbody>
        </table>
    </div>

This is my ajax script

<script>
    $.get("./../incomingRequestList.php", function(data, status){
        var obj = jQuery.parseJSON(data);
        for($i=0; $i<obj.length; $i++){
            $response +=  "<tr><td>1</td><td></td><td></td><td></td><td></td><td></td><td></td></tr>";
        }

        $('#result').html($response);
    });
</script>

How can i overcome this issue. I am unable to find out why its wrong.

3
  • Where're the variable declarations: var $i and var $response = "" ? Commented Aug 13, 2015 at 17:27
  • 1
    $response not defined Commented Aug 13, 2015 at 17:27
  • 1
    Yes I define $response = ""; great small mistake lots of time loss thanks Commented Aug 13, 2015 at 17:29

1 Answer 1

3

The correct way to do it is:

<script>
    $.get("./../incomingRequestList.php", function(data, status){
        var obj = jQuery.parseJSON(data);
        var response = '';
        for(i=0; i<obj.length; i++){
            response +=  "<tr><td>"+obj.number+"</td><td></td><td></td><td></td><td></td><td></td><td></td></tr>";
        }

        $('#result').html(response);
    });
</script>
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks Great Mistake :P)

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.