Build a simple webpage ebeded TinyMCE.
The html part.
<form method="post" action="dump.php">
<div id="main">
<div id="container_left">
<textarea id="mytextarea"></textarea>
<input id="submit" type="submit" value="submit">
</div>
<div id="show_right"></div>
</div>
</form>
The javascript part.
<script src="tinymce/tinymce.min.js"></script>
<script type="text/javascript">
tinymce.init({
selector: "textarea",
height: 250,
plugins: [
"code advlist autolink lists link image charmap print preview anchor",
"searchreplace visualblocks code fullscreen",
"insertdatetime media table contextmenu paste"
],
toolbar: "code insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image",
setup: function (editor) {
editor.on('init keydown change', function (e) {
document.getElementById('show_right').innerText = editor.getContent();
});
}
});
</script>
Now i want to print content in the TinyMCE's editor , after you click the submit button.
The dump.php
<?php
print_r($_POST);
?>
Why nothing print by dump.php?
I can send info to the dump.php via ajax method.
1.Remove <form method="post" action="dump.php"></form> in html part.
2.Add the following js code in the javascript part.
<script>
function send(){
var data = tinyMCE.get('mytextarea').getContent();
var ajax = new XMLHttpRequest();
ajax.open('POST','dump.php',false);
ajax.setRequestHeader('Content-type','application/x-www-form-urlencoded');
ajax.send('data='+data);
}
ob = document.getElementById("submit");
ob.addEventListener("click",send);
</script>
I have tried that it can pass content which i type in the textarea whose id is mytextarea to dump.php and dump.php can print the array properly.
My issue is to pass content in tinymce's textarea to a PHP file directly ,instead of via ajax?
Do the work without ajax.
from How to pass content in tinymce's textarea to a PHP file directly instead of via ajax?
No comments:
Post a Comment