08-26-2013 03:27 PM
Hi
I am trying to to use ajax and/or json for Web service restful which I have build with the labview. However I get errors
For example. I have build a web service from a labview vi (z =x/y http://localhost:8080/math/devide/5/20 will give {Z:"4.000000"} )
I am getting errors for the attached html files.
Does anyone know how to get data from al labview web service with ajax or json?
Thanks...Eran
Solved! Go to Solution.
08-26-2013 06:21 PM
And the errors are....
Mike
08-27-2013 08:05 AM
Hi Mike
I get parserror however the readyState = 4 and the status = 200
Thanks...Eran
08-27-2013 08:53 AM
What version of LV are you working in and how are you generating the JSON?
Also, what does you LV code look like?
Mike...
08-27-2013 09:44 AM
Hello Mike
Attached an image of my code
I am using LV2012
About the JSON generation - you can see it in the files
Thanks...Eran
08-27-2013 09:55 AM
Maybe this is dumb, but.... i think the VI has to run continuously for the webservice to properly hook up.
As your VI obviously has no loop to repeat execution, i would investigate in this direction.
You should look into the examples shipped with LV for the web service.
Norbert
08-27-2013 09:56 AM
If I understand the javascript correctly, if the ajax call fails, you call an anonymous function that returns generates an alert with the status in it. Have you tried passing the data (which is also going to the function) to an alert?
In addition, my first thought would be to write a small LV program that uses th HTTP client VIs to try and access the same webapplication. This would also let you see exactly what LV is generating for JSON. It might be ill-formed - or the problem might be in the jquery call.
You could also try calling the xmlhttprequest method directly from the javascript.
Mike...
08-27-2013 09:58 AM
No, VIs that you set up in this way are called by the webapplication as needed. Plus, what he's doing - at least as far as the math example goes - is one of the examples.
Mike...
08-27-2013 10:04 AM
Mike,
i am wondering as my LV installation only provides two examples for Web Services: Weather Station and Address Book.
Both include a loop in their main VI which is only stopped once the web service access is terminated and the service stopped.
But if you have experience regarding this, you should be correct as my web service experience is, honestly, non-existant 😄
Norbert
08-27-2013 10:50 AM - edited 08-27-2013 10:53 AM
Ok, I see what you mean, but you are looking at two different things. In terms of the weather station example, there is a VI that is running all the time, but its there to generate simulated weather data and stuff it into what is essentially a functional global that is using a queue internally to store the data. The we service itself uses three VIs that form the web interface that HTTP clients - like browsers or other programs - use.
Note that with LV2013 this interface has changed significantly. For example, the web server is no longer a separate type of build specification but is a new kind of target - which actually makes a lot more sense that the old representation.
You'll also note that the build specification folder includes two EXE build specifications: One is for the client application that will read the weather data and one for the weather simulator which is generating the data that the web service is the accessing. This is important because (regardless of what version you are using) you don't want to put too much code in the web service. You should only see the web service as a different kind of user interface - it is not your whole applilcation.
Likewise, in either version the VIs that form the web interface do not have loops since their only job is to reply to a single HTTP method request. If you're interested in taking a peek at what is really going on behind the scenes, do a Google search on 'HTTP Methods'.
Mike...
PS: FWIT, it looks like the 2013 implementation of web services is much more complete than the previous releases, but it still doesn't address a basic problem that users in large corporations have to confront, which is their IT department telling them: "You want to put your own (adjectives like "little" or "toy" are often inserted here) web server online? In your dreams..."