LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Does anyone know how to get data from a Labview web service with ajax or JSON?

Solved!
Go to solution

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

 

Download All
0 Kudos
Message 1 of 16
(4,352 Views)

And the errors are....

 

Mike


Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
0 Kudos
Message 2 of 16
(4,330 Views)

Hi Mike

I get parserror however the readyState =  4 and the status = 200

Thanks...Eran

0 Kudos
Message 3 of 16
(4,310 Views)

What version of LV are you working in and how are you generating the JSON?

Also, what does you LV code look like?

 

Mike...


Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
0 Kudos
Message 4 of 16
(4,303 Views)

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

0 Kudos
Message 5 of 16
(4,298 Views)

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

Norbert
----------------------------------------------------------------------------------------------------
CEO: What exactly is stopping us from doing this?
Expert: Geometry
Marketing Manager: Just ignore it.
0 Kudos
Message 6 of 16
(4,283 Views)

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...


Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
0 Kudos
Message 7 of 16
(4,282 Views)

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...


Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
0 Kudos
Message 8 of 16
(4,279 Views)

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

Norbert
----------------------------------------------------------------------------------------------------
CEO: What exactly is stopping us from doing this?
Expert: Geometry
Marketing Manager: Just ignore it.
0 Kudos
Message 9 of 16
(4,277 Views)

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..."

 


Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
0 Kudos
Message 10 of 16
(4,264 Views)