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/

    评论

报告相同问题?

悬赏问题

  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制
  • ¥20 usb设备兼容性问题
  • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊
  • ¥15 安装svn网络有问题怎么办