Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>From the answer to my comment, my understanding is that you want to:</p> <ol> <li>Enter a file name into a form on your webpage. </li> <li>Dojo will then load that particular text file from your sever.</li> <li>The file then needs to be displayed on the screen in some sort of editing componant.</li> <li>The user then needs the facility to post the file back to the server.</li> </ol> <p>I would have thought that the best approach is to use <a href="http://dojotoolkit.org/documentation/tutorials/1.8/ajax/" rel="nofollow">dojo/request</a> to get the text file and then use it again to post it back. You could the various <a href="http://dojotoolkit.org/reference-guide/1.8/dijit/form.html#dijit-form" rel="nofollow">dojo dijits</a> to do the selecting and displaying.</p> <p>A very crude solution would be:</p> <pre><code>&lt;form data-dojo-type="dijit/form/Form"&gt; &lt;input type="text" id="fileName" data-dojo-type="dijit/form/TextBox" /&gt; &amp;nbsp;&lt;button data-dojo-type="dijit/form/Button" type="button"&gt;Get &lt;script type="dojo/on" data-dojo-event="click"&gt; require([ "dijit/registry", "dojo/request" ], function(registry, request) { var fileName = registry.byId("fileName").get("value"); request(fileName, { "handleAs": "text" }).then(function(content){ registry.byId("content").set("value", content); }); }); &lt;/script&gt; &lt;/button&gt;&lt;br /&gt;&lt;br /&gt; &lt;textarea id="content" data-dojo-type="dijit/form/TextBox"&gt;&lt;/textarea&gt; &lt;button data-dojo-type="dijit/form/Button" type="button"&gt;Send &lt;script type="dojo/on" data-dojo-event="click"&gt; require([ "dijit/registry", "dojo/request" ], function(registry, request) { var content = registry.byId("content").get("value"); request("myhandler.php", { "method": "post", "data": { "content": content } }).then(function(content){ // deal with the response }); }); &lt;/script&gt; &lt;/button&gt; &lt;/form&gt; </code></pre> <p>This will load a text file with the filename you enter in the text box (after clicking <em>get</em>). The content is loaded into the textarea for editing and can be sent back to a server script by clicking <em>send</em>.</p> <p>This is as I said, "a very crude example". However, it shows the use of <a href="http://dojotoolkit.org/documentation/tutorials/1.8/ajax/" rel="nofollow">dojo/request</a> to receive and post information to/from the server. Obviously, you'd want a more sophisticated solution that hides/shows widgets at the appropriate moment. You would probably want to replace the filename textbox with a some sort of combo populated via your server code...etc, etc.</p> <p>I'd suggest you <a href="http://dojotoolkit.org/documentation/tutorials/1.8/templated/" rel="nofollow">write your own widget</a> to encapsulate the whole operation, rather than declare it all in markup. You could use <a href="http://dojotoolkit.org/documentation/tutorials/1.8/ajax/" rel="nofollow">dojo/request</a> to load a json file from the server to populate a combo box to select the file. You'd also want to ensure the information being posted back is from a trusted source.</p> <p><strong>Important!</strong> This will only work if the textfile and you webpage are residing on the same domain. It will not work for cross-domain requests. If you want to do cross-domain you'll need to create a json solution.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload