I'm developing a Raspberry Pi weather station with the intent to display weather measurements using some nice open source gauge tools. The RPi is sending a text file to my ISP server that I use so a php file can parse the data and use which measurements I choose to display with the gauges on a webpage I'm creating. At the end of the php file, I'm using:
echo json_encode($weatherstat);
to encode the data properly. I've successfully set up an AJAX call in my webpage file to execute the php parsing file. I use the javascrip 'alert' command to display the data. The alert does show the data is being transferred.
Here is the javascript code:
wxstats = new Array()
$.ajax({
url: 'phpParseWxStats1.php',
datatype: 'json',
success: function(data) {
// everything is ok
alert('AJAX call successful...' + data)
wxstats = JSON.parse(data);
},
error: function() {
alert('There was some error performing the AJAX call!')
}
});
dirdeg = wxstats[3];
gust = wxstats[1];
temp = wxstats[20];
The data appearing in the alert window is correct but each data-point is separated by commas. After reading a number of other postings, I tried using the 'wxstats = JSON.parse(data);' line hoping it would parse the data and put it into the wxstats array I declared. It is not working.
Looking for how to correct this and the code to put the string or whatever is being returned into the wxstats array I declared. I'm struggling with this. I've searched many other posting and I'm not finding a solution that fits my requirements. I just need a simple solution!