Vote count:
0
i have a textarea and a save button..I want to capture the data in the textarea and write it to a file but am getting problems..Am getting problems in writing the code for ajax.Note i am not using form.
<textarea id="display" name="display" style="overflow:auto;resize:none" rows="35" cols="40"><?php echo $data;?></textarea>
<input type="button" name="Save" value="Save" onclick="save_data()"/>
This is the Ajax i wrote...
function save_data(){
var ajaxadd;
ajaxadd=new XMLHttpRequest();
var url = "save.php";
ajaxadd.open("GET",url,true);
ajaxadd.onreadystatechange = function(){
if(ajaxadd.readyState==4){
document.getElementById('display').value = ajaxadd.responseText;
}
}
ajaxadd.send(null);
alert("Item successfully ADDED!");
}
This is the save.php
<?php
if(!empty($_POST['data'])){
$data = $_POST['data'];
$fname ="XHTML_file.xhtml";
$file = fopen($fname, 'w');//creates new file
fwrite($file, $data);
fclose($file);
}
?>
asked 54 secs ago
Aucun commentaire:
Enregistrer un commentaire