Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Dec 2011
    Posts
    201
    Thanks
    12
    Thanked 26 Times in 26 Posts

    revisiting old project, ajax success

    present goal: Use AJAX/Jquery to prepend 1 new row to my table every 10 seconds, then knock off the last row.

    future goal: use the data from each row to place a point on a map.

    current issues: removing the onclick and setting limits/timers on the prepend function so the table is only populated with one row every 10 seconds vs populating the table with everything that the data.php file has, does that make sense?


    Code:
    $(document).ready(function() {
    	$('#btnAdd').click(function getData() {
    		
    		// get data 
    		$.ajax({ 
    			url: '/ajax/data.php', 
    			type: "GET", 
    			cache: false, 
    			dataType: "json",
    			error: function(data) { 
    				$("div#error").html('error: '+data); 
    			}, 
    			success: function postData(jsonObj) { 
    				
    				$.each(jsonObj, function(index, value) { 
    					var newRow = $("<tr><td>"+value.icon+"</td><td>"+value.app+"</td><td>"+value.timestamp+"</td><td>"+value.location+"</td><td>"+value.comments+"</td></tr>"); 
    					$("#mainTable tbody").prepend(newRow); 
    				}); 
    			}		 
    		});
    	});
    });
    http://pastebin.com/jiu4RtVv

  • #2
    New Coder
    Join Date
    Apr 2012
    Location
    United Kingdom
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts
    an easier way in my opinion would be to write this in PHP as a server process.

    It would be quite simply a script with a do loop:

    Code:
    do {
    
        // do stuff
        // try to perform actions with function calls which ALWAYS return
        // even if only returning null. Try to clean up any variables used by 
        // setting them to NULL or using unset(). Will help save RAM!
    
        //wait
        sleep ( 10 );
    
    } while (1);
    maybe another script to load it
    Code:
    exec ( 'php myscript.php > /dev/null &' );
    
    exit();
    Providing quality professional Mobile Applications, Web Applications and Website Development Services.

  • #3
    New Coder
    Join Date
    Apr 2012
    Location
    United Kingdom
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Perhaps my suggestion wouldn't work for what you need there, slept on it! LOL
    Providing quality professional Mobile Applications, Web Applications and Website Development Services.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •