Source language: Translate to:

StrParse error

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

Moderator: Neosoft Support

StrParse error

Postby Ronnie » Fri Aug 19, 2016 1:40 am

Hi,
I'm testing the ability to read the testfile.txt from a server. The [TestArray] successfully shows the result (content data). I wanted to split/parse the result into an array. However, there was an error in Console log, "TypeError: Object doesn't support property or method 'split' at StrParse (file://...neoapp.min.js:2:933) at..."


========
Button 1
========
BeginJS
var req = new XMLHttpRequest();
req.open('GET', 'http://sampledomainname.com/testfile.txt', false);
req.send(null);
if (req.readyState==4);
$rootScope.TestVar = req.responseText;
$rootScope.TestArray = $rootScope.TestVar.split("\r\n");
EndJS

CreateArray [Items] ""
StrParse "[TestArray]" "~" [Items]


Any advice appreciated.
Thanks!
Ronnie
 
Posts: 6
Joined: Thu May 19, 2005 4:06 pm

Re: StrParse error

Postby luishp » Fri Aug 19, 2016 2:14 am

At first sight it seem to me that this:
Code: Select all
if (req.readyState==4);
$rootScope.TestVar = req.responseText;
$rootScope.TestArray = $rootScope.TestVar.split("\r\n");


should be like this:
Code: Select all
if (req.readyState==4){
  $rootScope.TestVar = req.responseText;
  $rootScope.TestArray = $rootScope.TestVar.split("\r\n");
}


Also keep in mind that JavaScript actions are executed even if the previous one has not finished yet.
For that reason there are usually callback functions. Functions that are executed once a download or any other time consuming process has ended.

Try to use two buttons: one for loading the text file and the other one to split the content
Luis Hernández - SinLios Soluciones Digitales
http://sinlios.com
User avatar
luishp
 
Posts: 361
Joined: Wed May 23, 2007 10:17 am
Location: Spain

Re: StrParse error

Postby Ronnie » Fri Aug 19, 2016 7:53 am

Hi Luishp,
Thanks. Will explore your suggestions. Am new to Javascript... But given time, I believe it should be easier.

Regards
Ronnie
Ronnie
 
Posts: 6
Joined: Thu May 19, 2005 4:06 pm

Re: StrParse error

Postby luishp » Sat Aug 20, 2016 2:04 am

Ronnie try using JQuery (included in NeoAppBuilder) instead of plain JavaScript.
It simplifies a lot many tasks. Take a look here:

http://www.w3schools.com/jquery/jquery_ajax_load.asp
Luis Hernández - SinLios Soluciones Digitales
http://sinlios.com
User avatar
luishp
 
Posts: 361
Joined: Wed May 23, 2007 10:17 am
Location: Spain


Return to General NeoAppBuilder Discussion

Who is online

Users browsing this forum: No registered users and 1 guest