Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

i have a function like below

in this ajax will work only one time. ie, when i=0

i want to work it for 10 times . can anybody help me?

<script type="text/javascript">
    $(document).ready(function () {
        var date, category, time, comments;
        $('#Save').click(function () {
            for (var i = 0; i < 10; 1++) {
                date = $('#list tr #date' + i).val();
                category = $('#list tr #category' + i).val();
                time = $('#list tr #time' + i).val();
                comments = $('#list tr #comments' + i).val();
                $.ajax({
                    url: 'http://localhost:1796/api/WorkStatus/',
                    type: "Post",
                    data: JSON.stringify([date, category, time, comments]),
                    contentType: 'application/json; charset=utf-8',
                    success: function () {
                       
                    }
                });
            }

        });
    });
</script>
Posted
Comments
Er. Puneet Goel 9-Apr-14 4:05am    
what actually you trying to do?

1 solution

You should collect in your for all dates, categories, times and comments into 4 arrays then to invoke only one AJAX call with these 4 arrays as parameters, and of course also to change the existing code from the controller.
 
Share this answer
 
Comments
Kunjammu 9-Apr-14 4:42am    
thank u...it will work. my code is working now. i made a mistake in my for loop. i used 1++ instead of i++. This mistake take my 2 hrs. :(

anyway thank u so much
Raul Iloc 9-Apr-14 4:47am    
Welcome, but I strongly recommend you to optimize your code by using only one AJAX call in place of 10, because each call (even if is AJAX) go to the web server, then there are some processing on the server (recreating of the controller class, executing the controller method and maybe accessing the database), then the result is sent back to browser!
Kunjammu 9-Apr-14 4:49am    
okay..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900