I'm just a front-end developer and I have no knowledge in PHP. Is there a way in JavaScript or jQuery that I can save data (something like a string) to the source directory?
-
Do you use an external api or do you want to save into a file or database directly? Please, give us some more informations.Sebastian Witeczek– Sebastian Witeczek2017-02-21 12:44:56 +00:00Commented Feb 21, 2017 at 12:44
-
Mark as answer if is helps you to solve your problem or give details what is not as it should becodtex– codtex2017-02-24 15:34:42 +00:00Commented Feb 24, 2017 at 15:34
Add a comment
|
1 Answer
Javascript is a client side programming language so it can't actually make changes to the server alone. The easiest way to achieve this would be using PHP.
What exactly are you trying to save and in what format do you want to save it? If you are saving a string to a text file for example, use AJAX to send it to a php file:
$.post( "saver.php", { string: myString})
.done(function( data ) {
//Code to be executed when complete
});
Then in a php file called saver.php
<?php
if($_POST['string']){
echo file_put_contents("myfile.txt",$_POST['string']);
} ?>
as a very basic example.
3 Comments
Lan Mai
Yes I'm trying just to save a string
Hunter
When you say save, how is it meant to be saved? Just being wrote to a text file? If so the above example should put you on the correct road.
Lan Mai
Yes it should be wrote to a text file. Then we can use Javascript to get the data from what we saved.