ReadFile: Difference between revisions

From NSB App Studio
Jump to navigation Jump to search
m James moved page Readfile to ReadFile: Changing to the canonical case.
Brendon (talk | contribs)
No edit summary
Line 1: Line 1:
READFILE (''filename''[,''method''])
ReadFile (''filename''[,''method''])


'''Description'''
== Description ==


NOTE: This function can be replaced by the Ajax() function.
Note: This function can be replaced by the Ajax() function.


READFILE will read filename which can either be deployed with the app or be on the same server as the app. If the file is to be deployed with the app, include it in the manifest. This function will only work when deployed to a website: it will not work when running in the local browser.  
ReadFile will read filename which can either be deployed with the app or be on the same server as the app. If the file is to be deployed with the app, include it in the manifest. This function will only work when deployed to a website: it will not work when running in the local browser.  


Use ''method'' to define the access method. Usually this parameter can be left out: the default is GET. The next most common value for this is POST. POST responses are never cached, whereas GET responses can be. POST also allows larger data transfers. Other methods are CONNECT, DELETE, HEAD, OPTIONS, PUT, TRACE, or TRACK. For more information on these options, look up XMLHttpRequest on the web. The function is based on XMLHttpRequest. See the ReadFile.nsx sample.
Use ''method'' to define the access method. Usually this parameter can be left out: the default is Get. The next most common value for this is Post. Post responses are never cached, whereas Get responses can be. Post also allows larger data transfers. Other methods are Connect, Delete, Head, Options, Put, Trace, or Track. For more information on these options, look up XMLHttpRequest on the web. The function is based on XMLHttpRequest. See the ReadFile.nsx sample.


It returns two values: .status = 0 or 200 if the file was read successfully and .responseText which has the entire contents of the file. If the file is not read successfully, a different status code is returned in .status.
It returns two values: .status = 0 or 200 if the file was read successfully and .responseText which has the entire contents of the file. If the file is not read successfully, a different status code is returned in .status.


There is no equivilent WRITEFILE. Use SQL, LOCALSTORAGE or the PhoneGap API to save data.
There is no equivilent WriteFile. Use [[sql|SQL]], [[localestorage|LocalStorage]] or the PhoneGap API to save data.


'''Example'''
== Example ==


<pre>
<pre>
REM READFILE example
Rem ReadfileFile example
filename="g.txt"
filename="g.txt"
req=ReadFile(filename)
req=ReadFile(filename)
Line 26: Line 26:
</pre>
</pre>


'''Related Items'''
== Related Items ==


[[ajax|AJAX]], [[localstorage|LOCALSTORAGE]], [[sql|SQL]]
[[ajax|AJAX]], [[localstorage|LOCALSTORAGE]], [[sql|SQL]]
[[Category:Language Reference]]

Revision as of 02:46, 17 August 2012

ReadFile (filename[,method])

Description

Note: This function can be replaced by the Ajax() function.

ReadFile will read filename which can either be deployed with the app or be on the same server as the app. If the file is to be deployed with the app, include it in the manifest. This function will only work when deployed to a website: it will not work when running in the local browser.

Use method to define the access method. Usually this parameter can be left out: the default is Get. The next most common value for this is Post. Post responses are never cached, whereas Get responses can be. Post also allows larger data transfers. Other methods are Connect, Delete, Head, Options, Put, Trace, or Track. For more information on these options, look up XMLHttpRequest on the web. The function is based on XMLHttpRequest. See the ReadFile.nsx sample.

It returns two values: .status = 0 or 200 if the file was read successfully and .responseText which has the entire contents of the file. If the file is not read successfully, a different status code is returned in .status.

There is no equivilent WriteFile. Use SQL, LocalStorage or the PhoneGap API to save data.

Example

Rem ReadfileFile example
filename="g.txt"
req=ReadFile(filename)
If req.status=200 Then
  MsgBox req.responseText
Else
  MsgBox "File could not be read"
End If

Related Items

AJAX, LOCALSTORAGE, SQL