必承其重 | 欲带皇冠 2013-07-19 05:49 采纳率: 0%
浏览 24

在JavaScript中调用php

Hi friends I have a PHP file as Shown below and I need to call a stored procedure inside javascript ie When i confirm yes I need to call the stored procedure . How should I include the following php code in IF loop of js(ie when i confirm yes)

This is the stored procedure:

 $sql = "CALL procedure(?);";
 $parameters = array($buyer_user_id);
 $query = $this->db->query($sql, $parameters);

This is the PHP file:

<?php
echo "<script>if (confirm('are u sure ?')) {";
echo "}";
echo " else {";
echo "}</script>";
?>
  • 写回答

1条回答 默认 最新

  • DragonWar% 2013-07-19 05:54
    关注

    You need to use AJAX:

    <script type="text/javascript">
        if (confirm('Are you sure?')) {
             var request = window.XMLHttpRequest() ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");
    
             request.open("POST", "phpfile.php", true);
             request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
             request.onreadystatechange = function () {
                 if (request.readyState == 4 && (request.status == 200 || request.status == 0 /*Fixes a FF bug*/)) {
                     alert(request.responseText); // should return "example1-example2"
                 }
             }
             request.send("data1=example1&data2=example2"); // you can send data here
        }
    </script>
    

    phpfile.php:

    <?php
         return $_POST['data1'] . "-" . $_POST['data2'];
    ?>
    

    I really dislike how complicated traditional AJAX is compared to using a library, but hope this gave you the idea.

    评论

报告相同问题?

悬赏问题

  • ¥15 is not in the mmseg::model registry。报错,模型注册表找不到自定义模块。
  • ¥15 安装quartus II18.1时弹出此error,怎么解决?
  • ¥15 keil官网下载psn序列号在哪
  • ¥15 想用adb命令做一个通话软件,播放录音
  • ¥30 Pytorch深度学习服务器跑不通问题解决?
  • ¥15 部分客户订单定位有误的问题
  • ¥15 如何在maya程序中利用python编写领子和褶裥的模型的方法
  • ¥15 Bug traq 数据包 大概什么价
  • ¥15 在anaconda上pytorch和paddle paddle下载报错
  • ¥25 自动填写QQ腾讯文档收集表