0

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?

2
  • Do you use an external api or do you want to save into a file or database directly? Please, give us some more informations. Commented 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 be Commented Feb 24, 2017 at 15:34

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

3 Comments

Yes I'm trying just to save a string
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.
Yes it should be wrote to a text file. Then we can use Javascript to get the data from what we saved.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.