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 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Feb 2014
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    why isn't this working, trying to make an array struct of data using ajax calls

    When I run this code, it will not even run the first line of the ajax protocol. I am printing out the main recieved string and it stays at a white screen.

    main page script
    Code:
    <p id="table"></p>
    
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js"></script>
    <script>
    
    
    var devicelist = new Array();
    
    var int1 = setInterval(function()
    {
    	$.get( "getdevices.php", function(data) 
    	{
    		var devices = data;
    		document.getElementById("table").innerHTML=devices;
    		//devices is a string of all devices along with data types
    		devices = devices.split("\n");
    		//devices is now an array of all devices, each device is a string of its datatypes
    		for(i = 0; i< devices.length; i++)
    		{
    			devicelist[i] = new Array();
    			//device i is now an array
    			devicelist[i] = devices[i].split(",");
    			//device i is now an array of its datatypes
    			for(j = 1; j < devicelist[i].length; j++)
    			{
    				//make data path for data request, getdevicetype, q id = device name
    				var getstring = "get" + devicelist[i][j] + ".php?q=" + devicelist[i][0] + ".php";
    				$.get(getstring,function(data)
    				{
    					var dvalues = data; //data is a string of lines with data
    					dvalues = dvalues.split("\n");
    					//dvalues is now an array of strings, each a line
                    	var data_l = dvalues.length - 1;
    					dvalues = dvalues[data_l].split(",");
    					//dvalues is now an of the last line seperated by a comma
    					devicelist[i][j] = new Array();
    					//device i, datatype j is now an array
    					devicelist[i][j] = dvalues;
    					//device i, datatype j is now an array of the last line of data values
    				});
    			}
    		}
    	});
    	//make_table("table");
    },250);
    </script>
    test request scripts:
    Code:
    gettacc.php
    <?php
    $q = $_REQUEST['q'];
    $readfile = $q . "_acc.txt";
    $file = file($readfile);
    $dataout = '';
    if(count($file) >= 500)
    {
    	for ($i = countfile($file) - 500; $i < count($file); $i++) 
    	{
    		$dataout = $dataout . $file[$i];
    	}
    }
    else
    {
    	for ($i = 0; $i < count($file); $i++) 
    	{
    		$dataout = $dataout . $file[$i];
    	}
    }
    echo $dataout;
    ?>
    
    getecg.php:
    <?php
    $q = $_REQUEST['q'];
    $readfile = $q . "_ecg.txt";
    $file = file($readfile);
    $dataout = '';
    if(count($file) >= 5000)
    {
    	for ($i = countfile($file) - 5000; $i < count($file); $i++) 
    	{
    		$dataout = $dataout . $file[$i];
    	}
    }
    else
    {
    	for ($i = 0; $i < count($file); $i++) 
    	{
    		$dataout = $dataout . $file[$i];
    	}
    }
    echo $dataout;
    ?>
    
    getdevices.php:
    <?php
    $dataout = file_get_contents("devices.txt");
    echo $dataout;
    ?>

    test database files:, first part of file name is request device id
    devices.txt: first piece of data on each line is device name, followed by datatypes
    123,ecg,acc
    234,ecg,acc

    there are four files for each piece of data, 2 for each device, each line is a device in devices.txt
    it wont even print out the string requested from devices.txt

  • #2
    Regular Coder
    Join Date
    Jan 2013
    Location
    Sunnyvale, CA
    Posts
    201
    Thanks
    11
    Thanked 10 Times in 10 Posts
    DEBUG!

    Remove your code from the timeout and check to see if the web service is responding as expected.


  •  

    Posting Permissions

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