weixin_33737134 2014-06-25 09:53 采纳率: 0%
浏览 18

用Ajax执行php文件

When I click on "Register Now" Button, I want to execute 'input.php' in which I have code to insert my data to the database and show a success message. I don't want to leave current page.

<input type="button" id="confirm" value="Register Now" class="button">

<script type="text/javascript">
$(document).ready(function() {
  $("#confirm").click(function() {
    <?php
    include 'input.php';
    ?>
    alert ("data Added successfully.");
  });
});
</script>

My code is giving me "data Added successfully" message but PHP file hasn't executed and no data is added to the database. All necessary data is in session variables.

  • 写回答

6条回答 默认 最新

  • weixin_33738578 2014-06-25 09:57
    关注

    To execute a Php script from javascript, you have to use Ajax.

    the following code :

    $("#confirm").click(function() {
        <?php
        include 'input.php';
        ?>
        alert ("data Added successfully.");
      });
    

    will not work

    http://api.jquery.com/jquery.ajax/

    评论

报告相同问题?