I want to write a javascript string into a file called preview.html in my server. I am trying to use the Get method to pass the javascript string to php but it doesn't seem to be working. I am using aloha editor and the javascript string Result contains the content entered by the user.
This is a simple version of my work which is not working, any idea why?:
<script type="text/javascript">
// make the div editable by user
Aloha.ready(function() {
$('#title').aloha();
});
// When submit is clicked
function onSubmit() {
var e = Aloha.getEditableById('title');
var Result = e.getContents();
location.href="page.php?Result=" + Result;
}
</script>
<div id="title">Title. Click to Edit.</div>
<a href="javascript:onSubmit();">Submit</a>
<?php
$fp = fopen('preview.html', 'w');
$r = $_GET['Result'];
fwrite($fp, $r);
fclose($fp);?>
You could use an ajax request to store the editable content. Here is a simple example with Aloha Editor: https://gist.github.com/1448270 This will save the data of multiple editables to a SQLite DB (from there it will be inserted into html)
There is an other demo app which saves the data to a file: https://github.com/alohaeditor/Aloha-Editor/blob/dev/src/demo/demo-app/app/save-to-file.php