LabVIEW Web UI Builder and Data Dashboard

cancel
Showing results for 
Search instead for 
Did you mean: 

parsererror for j query and Ajax of Labview Web Service

I am trying to to use Ajax and/or JSON for getting data from a Web service restful which I have build and deployed with the Labview software.

However I get errors (parsererror). For example. I have build a web service RESTFUL from a Labview vi

localhost:8080/math/divide/5/20 will give {"Z":4.000000} )

I get results when I run the web service with the browser (Chrome, Explorer,Safari or from Android application I have wrote) but I am getting errors for the below example.

When I use the source breakpoints the data read status is 4 and the data status is 200

I get in the console log the following massage:

Uncaught SyntaxError: Unexpected token :5&callback=jQuery15109152818964794278_1379778833104:1

does anyone know how should I call to a web service RESTFUL?

 

        url = "localhost:8080/math/divide/5/20&callback=?"

        $.getJSON(url,

 function (data) {

      }).done(function (data, status) {

        // doing something something

          

  }).fail

            (function (data,status) {

               alert(status);

            });

0 Kudos
Message 1 of 6
(8,048 Views)

Your URL isn't properly formatted. You can't have an ampersand (&) before the question mark (?). All variables that you want sent to the web service as part of a query string need to come after the ?.

0 Kudos
Message 2 of 6
(8,041 Views)

Hi

I do not think that this is the problem

When I replace the URL I succeed to get the data...see the below example 

do you have an example for js or jquery script?

 

<script src="jquery-1.10.2.js"></script>
<script src="jquery-1.10.2.min.map"></script>

<script>
$(function () {
  var url = "http://api.rottentomatoes.com/api/public/v1.0/movies.json?apikey=g2hukrh8pvy4q2pmv8qyy9tc&q=free+wil...
  $.getJSON(url,
 function (data) {

                      }).done(function (data, status) {
                                    var arr = data.movies;
                                    var dim = arr.length;
                                    var str = "";
                                    var nstr = null;
                                    for (i = 0; i < dim; i++) {
                                    nstr = data.movies[i].title + "\n";
                                    str += nstr;
                                   }
                                      alert(str);
                    }).fail
                         (function (data, status) {
                                                            alert(status);
                                                              });
                });
</script>

0 Kudos
Message 3 of 6
(8,034 Views)

Hey Eran1965,

 

Are you trying to use a LabVIEW Web Service with JSONP and call it from a different origin?  Or are you planning on hosting the JQuery with your Web Service in LabVIEW?  

 

Here is a good example of using JavaScript with LabVIEW that should help get you moving in the right direction.

 

Best,

KiraT

0 Kudos
Message 4 of 6
(8,031 Views)

Hi

I am trying to call it from a differnt origent and hopfully in the future to use it in windows Azure or other hosting.

 

About the example, it did not worked/

I have to correct the example bye adding <title></title> to the header and to change the url to http://localhost:8080/ChartsService/Random.

un fortunaly the xmlhttp.status=0;

 

can you think about a solution?

Thanks...Eran

0 Kudos
Message 5 of 6
(8,008 Views)

Hey Eran,

 

Did you modify the example to move the HTML and JavaScript out of the LabVIEW project?  If that is the case, I would expect it not to work.  You are then not adhearing to the same origin policy and the request will fail.  

 

I dont know your specific use case for not using the same origin, but I believe that you will need to use JSONP to have proper execution.  There is no built in terminal mode for JSONP, so you will have to stream your responses and to add the correct tags before sending the response.  The JSON Primitives in LabVIEW 2013 are very helpful for formatting the JSON. 

 

Kira

0 Kudos
Message 6 of 6
(8,000 Views)