07-14-2009 02:34 PM
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...
07-14-2009 02:55 PM - edited 07-14-2009 03:04 PM
07-15-2009 07:06 AM
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...
02-01-2011 12:09 PM
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
03-19-2011 12:22 AM
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?
03-19-2011 12:24 AM
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.
03-20-2011 06:10 PM
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.
03-21-2011 08:56 AM
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. Just a thought...
Todd
03-21-2011 08:59 AM
@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. 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.
04-12-2011 02:39 PM
@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.