Source language: Translate to:

JS var to NeoAppBuilder var

General questions about NeoAppBuilder - our rapid application development tool for building HTML5, web and mobile apps.

Moderator: Neosoft Support

JS var to NeoAppBuilder var

Postby djmarkes » Sat Jan 24, 2015 3:46 pm

I'm trying to read through JavaScript a text file hosted on my server. The code works fine but do not know how to do to bring the text as a string to a variable NeoAppBuilder, later to play with it with the program functions.

The code:

Code: Select all
 var req = new XMLHttpRequest();
  req.open('GET', 'http://www.jm-style.net/test.txt', false);
  req.send(null);
  if (req.readyState==4) alert(req.responseText);


The alert box works perfect.

Thnaks! :mrgreen:
Diseño gráfico y Web profesional
http://www.jm-style.net
User avatar
djmarkes
 
Posts: 187
Joined: Thu May 26, 2011 5:08 pm

Re: JS var to NeoAppBuilder var

Postby Gaev » Sat Jan 24, 2015 4:24 pm

djmarkes:

This code will help you to understand how variables in NeoAppBuilder space and Javascript space can be accessed ...
Code: Select all
SetVar [nabVar] "wxyz"
AlertBox "nabVar" "[nabVar]" ""

BeginJS
jsVar = "abcd";
alert("jsVar is " + jsVar);
$rootScope.nabVar = jsVar;
alert("js says nabVar is " + $rootScope.nabVar);
EndJS

AlertBox "new nabVar" "[nabVar]" ""


However, note that unrelated to the values of variables, I have discovered a small bug ... the popups from alert and AlertBox commands are NOT displayed in the expected order ... I observed this sequence and content ...

alert >>> jsVar is abcd
alert >>> js says nabVar is abcd
AlertBox >>> "new nabVar" "abcd"
AlertBox >>> ""nabVar" "wxyz"

... note that the javascript alerts popup first ... and the Title and Messages of the AlertBox popups appear to be messed up ... I will advise Dave of this separately.
User avatar
Gaev
 
Posts: 3728
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada

Re: JS var to NeoAppBuilder var

Postby djmarkes » Sat Jan 24, 2015 7:23 pm

Perfect Gaev! Thank you very much has worked very well using:

Code: Select all
$ rootScope.nabVar = req.responseText;


But before I said it worked perfect and if, but only in IE, Chrome did not get to load the app.

Is missing many things and hope they arrive slowly. But is now possible to do that? Read the contents of a remote txt, as we do in Neobook with InternetGet.

Greetings!
Diseño gráfico y Web profesional
http://www.jm-style.net
User avatar
djmarkes
 
Posts: 187
Joined: Thu May 26, 2011 5:08 pm

Re: JS var to NeoAppBuilder var

Postby Gaev » Sun Jan 25, 2015 1:03 pm

djmarkes:

But before I said it worked perfect and if, but only in IE, Chrome did not get to load the app.

Is missing many things and hope they arrive slowly. But is now possible to do that? Read the contents of a remote txt, as we do in Neobook with InternetGet.

I believe this is due to an internet policy known as Cross-Origin Resource Sharing (CORS) ... you may have been able to do things with older browsers (like IE versions in Windows XP) ... but modern Browsers automatically enforce this policy.

Here are some links that explain it ...

http://en.wikipedia.org/wiki/Cross-orig ... ce_sharing
https://developer.mozilla.org/en-US/doc ... ntrol_CORS

Last night, I found that jQuery methods .load() and .get() did not allow me to fetch data in a .txt file on my website ... but was able to do so with same file in the App's folder.

So, it looks like you have to have two identical copies of such (text) files ... one for testing locally ... and the other for when you run it as a Web Application ... no idea what you do if you want to run it as a (downloaded) App.
User avatar
Gaev
 
Posts: 3728
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada

Re: JS var to NeoAppBuilder var

Postby Neosoft Support » Mon Jan 26, 2015 12:23 pm

note that the javascript alerts popup first ...


This happens because JavaScript does not really have a way to pause execution and wait for user to do something. The one exception is the JavaScript alert() message. It breaks this rule and will suspend execution while the alert box is displayed, but other JS functions (like NeoAppBuilder's themed AlertBox) cannot. Typically, with JavaScript we would use a callback function that is executed after the AlertBox is closed to make sure the code executes in the correct order. Callbacks can be difficult to manage so I'm looking for another solution.
NeoSoft Support
Neosoft Support
NeoSoft Team
 
Posts: 5602
Joined: Thu Mar 31, 2005 10:48 pm
Location: Oregon, USA


Return to General NeoAppBuilder Discussion

Who is online

Users browsing this forum: No registered users and 1 guest