LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Can I call javascript alert popup from ESP script? (LabVIEW webservices)

Hi community,

 

The title says it all... is it possible to call a javascript function from an ESP script? (like <% alert("I am an alert box!"); %>, which is an invalid call indeed)

 

its possible to use: <% write('<script>alert("I am an alert box!")</script>'); %>, but this would be a hassle on longer scripts.

 

thanks!

0 Kudos
Message 1 of 5
(2,643 Views)

Hey 1984,

 

Would you be able to give some background on why you are trying to call JavaScript from your ESP script rather than the other way around and hosting some JavaScript in your LabVIEW based Web server and having that call the web method that calls the ESP?

 

 

 

0 Kudos
Message 2 of 5
(2,623 Views)

Hey Kira,

 

The thing is that I try to figure out things on my own about the webservices as I was not able to find proper tutorials about it. Therefore my implementation can be sub-optimal. My full scenario is this:

 

I have a main web page written in esp. This page displays some generic information plus it also has a login field (username + password). Once the user filled these fields he can POST the login to webservice. This webservice compares the username/pw with a list and if there is a match (login is successful) it redirects the user to the same page (with redirect 303) with injecting an variable "isAdmin" (boolean) to the page, so it can display some more information.

 

Also if the login was unsuccessful it inject another boolean "failedLogin" so the esp can check and call the javascript alert. So this is why I wanted to call JS from ESP.

 

Now I easily can imagine that this approach is debatable. What I think would be a lot better way is that somehow I grab the data from the user/pw fields send it directly to the VI which does the check and then returns the result so in the same javascript I can display the popup (or not). But I dont know how to call the VI directly from the page and also even if I set its output to XML or JSON I dont know how should I process it. I have not found any suitable tutorial on the net.

 

Or maybe there would be an even better way to do that. I am really keen to learn more about these stuff because my code starts to get convoluted and I believe there is a way to simplify it.

 

An thoughts would be appreciated.

0 Kudos
Message 3 of 5
(2,615 Views)

Hey 1984 .

I am trying to implement the same login /Pw checks through web services and there are not much tutorials out there to get some idea. Have you successfully done it. Can you please share some idea ?

0 Kudos
Message 4 of 5
(2,444 Views)

Ok... first of all you need to know that I am NOT a web developer of any kind so as I have realized this problem is probably neither the best and nor the most secure.

 

While using esp script seemed to be a nice idea first I ended up not using it for scripting. I have found it very hard to handle and hard to read so my ENTIRE html document (including javascript and everything else, except css) is generated in LV, in which I am very familiar with iterations etc. I still needed to use an esp file to display my generated contents, but I my esp file only had the followings:

 

<%

var htmldata = form["htmldata"];
write(htmldata);

%>

 

The code injecting my generated html content to the esp file was as simple as this:

html1.png

 

I assume you have some sort of an HTML knowledge, so you will understand whats going on in the following html script which was the part of my main html code. If you dont understand this then you gotta get some HTML knowledge first.

 

html2.png

 

In the project file under web project naeme (REMS) I had the follwing "path": web resources/visitor/login/rems_login.vi

 

The rems_login.vi received data from the html script show above with the POST method. The login VI had the follwings inside:

 

html3.png

 

If you load these snippets into labview you will have some missing VIs, but the idea as I have processed the data coming from my main HTML page is pretty clear. No matter what, at the end I redirect (303) to my main page after this VI finished running, but if the username / pw matches with the database entry then I put the info of the logged in user to the session variables. If not then I just filled the session variables with dummy data.

 

My main page always read the session variables and form the html page according to the actual credentials.

 

And once more: there could be cleaner implementations of the same solution, but I am not a web developer and the documentation / support of the webservices in labview is EXTREMELY poor. Actually I had to figure out everything on my own, so good luck.

 

I hope this helps.

 

 

0 Kudos
Message 5 of 5
(2,436 Views)