From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Web Services: AJAX (JavaScript), jQuery, HTML, and LV

Hello All,

 

I'm a total newbie to HTML and JavaScript but I really wanted to use LV Web Services. I spent some time trying to understand how to connect and use information served from a LV Web Service. I think I have made progress and thought I would share the results. Please do not hesitate to correct naive mistakes, offer insight, suggest shortcuts, or general help a webpage neophyte out...

 

I used the JavaScript library jQuery.js to get past some of the headaches involved with "get, post, etc" calls (proxy issues) and for XML parsing. For what it is worth I highly recommend this library.

 

Again, comments welcome! 

 

Cheers,

Jolt

 

Wirtten in 8.6.1 - can convert if needed...

0 Kudos
Message 1 of 13
(6,465 Views)
I just tried downloading and extracting these files - they work perfectly before zipping - but didn't work well for me when I retrieved them from my post. I'm not sure what the problem is and will have to revisit tomorrow. Apologies... 
Message Edited by Jolt on 07-14-2009 03:04 PM
0 Kudos
Message 2 of 13
(6,462 Views)

Please disregard the previous .zip - it appears as though I didn't check my file/project structure and missed a VI in the archive. I hope it is now fixed...

 

0 Kudos
Message 3 of 13
(6,443 Views)

Hey, Thanks for the post.

 

This is just what I needed.  Unfortunately I can't get this to work either.  I have been working for days to try and get my code to work but to no avail.  This code gives me the same problem as I am getting on my code.  No output on web page.  I have added the :8080 to the localhost in the index.htm.  I think this is a recent change.

So when I type : "http://localhost:8080/Demo/Array" into my web browser I get:

<Array>

<DBL>
<Val>22.000000</Val>
</DBL>

<DBL>
<Val>333.000000</Val>
</DBL>

<DBL>
<Val>4444.000000</Val>
</DBL>

<DBL>
<Val>55555.000000</Val>
</DBL>
</Array>

 

so I know that the NI web server is running and giving an output.  However when I run index.htm from within a browser with the $(document).ready modified to something simple:

 

   $(document).ready(function() {
        $.get("http://localhost:8080/Demo/Array",{},function(xml_2){
            alert("Success: " + xml_2);

        });
    });

 

 

I only get a ":" as an output. and an alert popup "Success " with nothing in xml_2.  I don't even get any errors in the error console.

 

Can any one help with the jQuery?  I would like to use json eventually but right now I would like to just get anything working!

 

While typing this a thought occurred to me to check this in IE.  It works!  Unfortunately I need it to work in FireFox.  Any thoughts?

 

Thanks

Todd

0 Kudos
Message 4 of 13
(6,142 Views)

I've been trying to get JSON working with my web service for about a week now. I cant get past the error case with the GET call.

 

        $.ajax({
            url: "http://localhost:8080/TestService/TestVI/",
            dataType: "jsonp",
            success: function (data) {
                alert(data.testQueue[0].user);
            },
            error: function (data) {
                alert("Error");
            }
        });

 

My web service should just return an array of tests with some basic information. The success case should just display the first user in the array, but it can't get past the error case.

 

I'm using the new Mozilla with Firebug to debug this problem and the callback is getting made, but like I said it's going straight to the error case.

 

Maybe this is a JQuery or JavaScrip problem really, but has anyone gotten jQuery to work with a JSON web service?

0 Kudos
Message 5 of 13
(6,048 Views)

One thing I forgot to mention is that I'm using JSON because when I tried to use XML, the declaration was never inserted into the XML file. JSON doesn't have a declaration.

0 Kudos
Message 6 of 13
(6,046 Views)

My bad, my problem is related to the "Same origin policy (http://en.wikipedia.org/wiki/Same_origin_policy)" using JSONP instead of JSON Should get around this, but LabVIEW's web service can't do JSONP, at least not natively.

0 Kudos
Message 7 of 13
(6,012 Views)

I came up against that too.  What I did was install PHP on my windows web server and then used this simple PHP proxy to talk to NI's web server.

 

http://benalman.com/projects/php-simple-proxy/

 

He has good examples to follow.  So good that even a caveman can do it.  Err... I mean I could do it. Smiley Surprised  Just a thought...

 

Todd

Message 8 of 13
(5,984 Views)

 


@toddho wrote:

I came up against that too.  What I did was install PHP on my windows web server and then used this simple PHP proxy to talk to NI's web server.

 

http://benalman.com/projects/php-simple-proxy/

 

He has good examples to follow.  So good that even a caveman can do it.  Err... I mean I could do it. Smiley Surprised  Just a thought...

 

Todd


Thanks for this. I was going to go the route of writing a something in Ruby to use a WAMP server to proxy the page. This seems a lot easier.

 

0 Kudos
Message 9 of 13
(5,981 Views)

 


@toddho wrote:

So when I type : "http://localhost:8080/Demo/Array" into my web browser I get:

<Array>

so I know that the NI web server is running and giving an output.  However when I run index.htm from within a browser with the $(document).ready modified to something simple:

 

   $(document).ready(function() {
        $.get("http://localhost:8080/Demo/Array",{},function(xml_2){
            alert("Success: " + xml_2);

        });
    });

 

 

Thanks

Todd


Don't include the server in your request. See if that works.

 

=====================
LabVIEW 2012


0 Kudos
Message 10 of 13
(5,925 Views)