0

I have this code to create a div inside a div with id container when you press a button

jquery

$(document).ready(function(){

  $("#add").click(function(){
      $('#container').append( $('<div>test</div>').addClass('div-color') );
  });

});

html

<div id="container">

</div>

How can I save the container div and the dynamically generated data in a file on the server? For example, if the user clicks the button twice, I want to save the following in a test.html file on the server (container div and everything that's in it).

<div id="container">
<div class="div-color">test</div>
<div class="div-color">test</div>
</div>

Guess it is not possible with javascript and if so, PHP is OK to use.

Xtreme
  • 1,601
  • 7
  • 27
  • 59
  • Did tried a search ? See [this](http://stackoverflow.com/q/15344624/1267304) and [this](http://stackoverflow.com/q/16873549/1267304). – DontVoteMeDown Dec 19 '13 at 20:11

1 Answers1

1

Try something like this

$.ajax({
  type: "POST",
  url: 'save.php',
  data: { content: $('#container').html() }
});

Then receive POST data and save it to file with php.

Mateusz Nowak
  • 4,021
  • 2
  • 25
  • 37