2016-11-27 10:12
浏览 39


It seems that this question has already been asked many times but none of the solution is working for me. I'm new to AJAX so maybe there are some basics that I've missed? Basically I just want to pass the content of an html paragraph to a PHP script and I don't want to use html form.

I have two files: tes.html

<!DOCTYPE html>
<script type="text/javascript" src = ""></script>
<script type="text/javascript" src=""></script>
<script type="text/javascript">
          var getContent = $("#text").html();
    <p id="text" contenteditable="true">This is the content</p>
    <a href="tes.php" target="_blank"><button id="post">post 2</button></a>

and tes.php

    if (isset($_POST['text'])) {
        $content = $_POST['text'];
        echo $content;
    } else {
        echo "no content";

After I clicked the Post button, in the PHP file it returns

Notice: Undefined index: text in C:\xampp\htdocs\projects\lab\tes.php on line 3.

Where did it go wrong? Really need your help guys. Thanks!

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

3条回答 默认 最新

相关推荐 更多相似问题