"Troubleshooting problem with fetching JSON data for Highcharts

As a relative newcomer to web development, my usual focus is on server-side work. Currently, I'm diving into a fun little electronic project where a Netduino server handles JSON requests within my LAN. The JSON response format from the Netduino looks like this:

[ { "sensor" : "bk", "temp" : "68.9000015", "time" : "01/01/2009 01:04:46"},{ "sensor" : "mt", "temp" : "69.0124969", "time" : "01/01/2009 01:04:46"},{ "sensor" : "hlt", "temp" : "68.9000015", "time" : "01/01/2009 01:04:46"} ]

I want to designate my sensors as series {bk, mt, hlt} (with two additional series not included in this response).

However, it seems that my AJAX request isn't sending GET requests to my Netduino. I've checked using HttpFox and haven't seen any activity towards 192.168.0.11...

This is the JavaScript code I am currently using:

//data arrays for holding the points
var HLT=[],
    MT =[],
    BK =[],
    PC =[],
    CL =[];
var chart;

//after DOM is loaded setup timeout to call the ajax method
$(document).ready(function() {
    setInterval(reqData, 5000);

    options.series[0].data = HLT;
    options.series[1].data = MT;
    options.series[2].data = BK;
    options.series[3].data = PC;
    options.series[4].data = CL;

    //call function to render the chart and setup the options
    renderChart();

});

//this function requests the data
function reqData(){
$.ajax({
    url: "http://192.168.0.11/"+Math.random(),//using math.random to avoid browser caching
    contentType: "application/json; charset=utf-8",             
    success: mergeData(data)
});
}

//this function merges the data and refreshes the table
function mergeData(data){
//$(this).addClass("done");
}

function renderChart(){
    chart = new Highcharts.Chart(options);
}

The chart displays when the page loads but I'm unable to see reqData being called. Any assistance would be greatly appreciated. Also, what would be a good way to update the series data? I have limited experience with JavaScript - could a foreach loop matching on series names work? My goal is to chart the temperature (y-axis) against datetime (x-axis) of the temperatures.

Thank you!

---edit 1/23/2012---

I apologize for not clearly stating the issue earlier. In this function:

//after DOM is loaded setup timeout to call the ajax method
$(document).ready(function() {
    setInterval(reqData, 5000);

    options.series[0].data = HLT;
    options.series[1].data = MT;
    options.series[2].data = BK;
    options.series[3].data = PC;
    options.series[4].data = CL;

    //call function to render the chart and setup the options
    renderChart();

});

The reqData() function doesn't seem to be triggering (confirmed by no GET requests to 192.168.0.11 in HttpFox), however, renderChart() is being executed. Any suggestions?

Answer №1

Did you upload information to a specific IP address? Is this IP within the domain where your webpage is hosted? If not, it might indicate an attempt to communicate with a different domain. In such instances, JSONP would be necessary for the operation to succeed. For more details on JSONP, refer to this link: http://api.jquery.com/jQuery.getJSON/

Answer №2

Is there a possibility that another issue is causing interference? The data request seems to be correct; I have included it in the following code snippet:

http://jsfiddle.net/exampleuser/abc123/

Have you noticed any JavaScript errors on your webpage?

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Trying to configure and use two joysticks at the same time using touch events

I have been grappling with this problem for the past two days. My current project involves using an HTML5/JS game engine called ImpactJS, and I came across a helpful plugin designed to create joystick touch zones for mobile devices. The basic concept is th ...

The function getSelection().focusNode does not function properly within a specified ID

My current code allows for text to be bolded and unbolded using Window.getSelection(). I found the initial solution here: Bold/unbold selected text using Window.getSelection() It works perfectly without any issues. However, when I tried to modify the code ...

How to convert a nested array of objects into a string using JavaScript for passing as a URL parameter

So, I'm dealing with a nested JSON array of objects here. My goal is to pass it as a parameter in the URL and then save it to my MongoDB database. However, when I tried doing that, it ended up being saved as [object object]. Does anyone know how to so ...

Displaying spinner until the entire section has finished loading

In order to display a loading spinner until all images in a specific section of the page have fully loaded, I am utilizing Django, jQuery, and Ajax technologies. The HTML structure consists of two main divs: On the left side, there is a table, while on t ...

There seems to be a glitch with jQuery on my Angular.js website

I'm trying to implement Masonry.js on my website, and although I've managed to make it work, the solution feels like a messy workaround and I can't quite figure out why it's functioning (and not functioning well). The primary issues I& ...

The console is showing an error message stating that the variable "i" is not

Currently, I am developing the dashboard for my discord.js bot. While working on it, I encountered an issue where a variable I created to select an array from my JSON file is being reported as undefined by the console. $(function() { $.getJSON( "./data/ ...

Transmitting data from a JavaScript array to PHP using JSON

Although this question may seem redundant, I found myself getting confused after reading numerous posts on the topic. (Apologies for that!) Essentially, my goal is to send a JavaScript array to a PHP file and then write that array to a text file. After som ...

Angular Group Formation Issue

I keep encountering the following error: formGroup expects a FormGroup instance. Please pass one in. This is how it looks in HTML: <mat-step [stepControl]="firstFormGroup"> <form [formGroup]="firstFormGroup"> And in my Typ ...

Enhancing TypeScript builtin objects in Netbeans using a custom plugin

While in the process of converting JavaScript code to TypeScript, I encountered a challenge with extending built-in objects using Object.defineProperty, such as String.prototype. Object.defineProperty(String.prototype, 'testFunc', { value: funct ...

Updating another component when an input value changes in React

I am currently learning React and I am facing a challenge in updating a component based on an input value. Previously, I had successfully done this using HTML and vanilla JavaScript. Now, I am trying to achieve the same functionality in React but encounter ...

angular primeng table has a checkbox to select all checkboxes

Is there a way to check all checkboxes in a table when the checkbox in the table header is clicked? I am currently utilizing angular 12 and primeNG table for this functionality. <p-table styleClass="text-sm" [value]="value" [loading] ...

Explore a JSON structure and identify the parent key of a specific key:value pair

I may be new to coding, but I've hit a roadblock and can't seem to find the solution - despite numerous attempts on Google and StackOverflow. Behold, a JSON object: const json = { "catalog:aardvark": { "severity": "minor" }, ...

Why does the Setter Getter class variable in Android's RecyclerView only retrieve the last object from JSON data?

I am having an issue with my Setter Getter class variable only capturing the last object from JSON. The goal is for it to store all JSON objects in the setter getter variable so that they can be transferred to a recyclerview. Below is a snippet of the cod ...

Issue with Bootstrap 5 Modal Overlay

I created a function that automatically generates a modal to save time and keep the code organized. This way, the HTML and JS related to the content of the modal are all in one PHP file, rather than mixed in with the file calling the modal: function new_mo ...

Numerous JQuery AJAX form submissions leading to individual outcomes

I have implemented a script on my page that handles form submissions for multiple forms by calling a specific action. Here is the script: $(function () { $('form').submit(function () { if ($(this).valid()) { $.ajax({ ...

What other ways can websockets be utilized besides comet?

Websockets offer a more efficient solution for comet (reverse Ajax, often achieved through long-polling). However, are there other ways we can utilize websockets? For instance: - Can websockets be used to facilitate communication between different bro ...

I'm encountering a status 415 error when trying to post to the Spotify API for tokens. Is there something I'm

My approach to interfacing with their API for the Authorization Code Flow is as follows: class func obtainAuthTokenPackage(authCode: String) throws { //Initiate a request var request = URLRequest(url: Gimme.theSpotify.urlFor(endpoint: .requestingT ...

Retrieve the data stored in an array of objects

code props.thumbnails.forEach(value=>{ console.log(value.photo.thumbnail_url); }) error TypeError: Cannot read property 'thumbnail_url' of undefined Trying to loop through props.thumbnails array and access the thumbnail_url pro ...

Loop through a collection of arrays that contain the same elements, and multiply each consecutive element by a specified value x

I've been diving into a challenging problem involving remarkable numbers, which are defined as A number that is equal to the sum of all its proper divisors -- provided one of them is negative. For instance, the proper divisors of 12 are 1, 2, 3, 4, 6 ...

Decompressing JSON data type document

I am currently facing an issue with deserializing a Json string to a custom class. Here is the structure of my json data: externDossierNr:"foo10" internDossierNr:"2016010" rapport:File testarray:Array[3] testword:42 __proto__:Object The fields externDoss ...