S
S
sHARek2018-03-19 10:53:02
PHP
sHARek, 2018-03-19 10:53:02

Save value contenteditable="true" + ajax + php. How?

Good afternoon.
Don't be too harsh, I'm new.
Is it possible to store the contenteditable="true" value via ajax in one index.php file, or is an additional file like obrabotka.php required?

Something like:

<?php
  $a = $_POST['txt'];
?>
<!DOCTYPE html>
<head>
<link rel="stylesheet" href="style.css">
<script type="text/javascript" src="jquery-3.3.1.min.js"></script>
</head>
<body>
<div id="main" contenteditable="true">Привет</div>
<p id="xx"></p>
<p><?php echo $a; ?></p>
<script type="text/javascript">
$( document ).ready(function() {
    $("#main").blur(function(){
    $.ajax({
      type: 'POST',
      url: 'index.php',
      data:txt=$("#main").text(),
      success:function(){
        $("#xx").html($("#main").text());
      }
    });
  });
});	
</script>
</body>
</html>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Stalker_RED, 2018-03-19
@Stalker_RED

It's possible, I'll allow it.

<php?
if (!empty($_POST['txt'])) {
 // здесь проверки, сохранение, вот это всё
}
,,,

To get a more detailed answer, you will have to try a little bit, and describe:
1. What are you trying to do
2. What is "save contenteditable="true" value"
3. And why do this on the server at all

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question