HttpWrite: Difference between revisions
Jump to navigation
Jump to search
(Reverted: Direct call to JS getRandomQuote was not wrong. That's what the ajax resource is for.) |
m (Reverted again: disregard last edit - it's not js) |
||
Line 32: | Line 32: | ||
</head> | </head> | ||
<body> | <body> | ||
<b>Random quote:</b> <* httpWrite( getRandomQuote | <b>Random quote:</b> <* httpWrite( call ( getThisResource(), "getRandomQuote" ) ) *> | ||
</body> | </body> | ||
</html> | </html> |
Revision as of 15:52, 27 October 2007
This function adds text to the output of the current HTML file of the HTTP interface.
Syntax
bool httpWrite ( string text )
Shortcut syntax
The following shortcut syntax is also supported:
[html] <* = text *>
which is equivalent to:
[html] <* httpWrite(text) *>
Required Arguments
- text: the string of text to be added to the page's output.
Returns
Returns true if the text was added to the output buffer successfully, false otherwise.
Example
This sample resource page will output a random quote from a player using a function previously exported to http from a Lua script in the resource.
[html] <html> <head> <* = call ( getResourceFromName("ajax"), "start", getResourceName(getThisResource()) ) *> </head> <body> <b>Random quote:</b> <* httpWrite( call ( getThisResource(), "getRandomQuote" ) ) *> </body> </html>
The first httpWrite call (in shortcut syntax) adds the links to scripts generated by the ajax resource, enabling use of the getRandomQuote function.
The second httpWrite call writes the quote generated by the function to the HTML output.
See Also
These functions can only be used from within lua blocks in HTML pages hosted by the server
- httpClear
- httpRequestLogin
- httpSetResponseCode
- httpSetResponseCookie
- httpSetResponseHeader
- httpWrite