Jquery Write To File Script - Jquery

How to write file in jquery?

Snippet Code


  
Rate this page :
  [ 0 votes]

Jquery does not have access for writing files due to security reasons. Here we pass the value through ajax, and with help of php we write the value in file. The below code is used to write in jquery file.

<script src="https://code.jquery.com/jquery-1.10.2.js"></script> <script type='text/javascript'> $(function(){ $('#btn').click(function(){ $.ajax({ type: "POST", url: "ajax-write.php", data:{name:'This is written text'}, success: function(data){ alert(data); } }); }); }); </script> <input type='button' value='Click to write file' id='btn'> ajax-write.php : <?php $myFile = "test.txt"; $file = fopen($myFile, 'w'); fwrite($file,$_POST['name']); fclose($file); echo $_POST['name']; ?>

Tags


Ask Questions

Ask Question