dongxi8993 2014-12-15 00:42
浏览 95

我的post方法在localhost中不起作用

I m trying to do post some data to php but it is not working and also i have checked chrome dev tool. That when i click the equal button it will appear this status: calculation.php method:OPTIONS status:(canceled) text/plain jquery.min.js:4 0 B 8 ms

I am not sure what is the problem. However it works in here : daciusa.org/pella/calc.html

 $(function () {
        var $show = $('#display');
        var currentDisplay = "";

        $show.val(0);


        $(document).on('click', 'button.number', function () {

            if ($show.val().length >= 8) {
                $show.val("Error");
            } else if ($show.val() == "Error") {
                $show.val("0");
            } else if ($.inArray($show.val(), ['+', '-', 'x', '/']) !== -1) {
                var addOp = $show.val();
                if (addOp) memory.push(addOp);
                $show.val($(this).val());
            } else {
                $show.val(($show.val() == "0" ? "" : $show.val()) + $(this).val());

            }
        });
        $("#clear").click(function () {
            $show.val("0");
        });
        $("#ce").click(function () {
            if ($show.val().length >= 2) {
                $show.val($show.val().substring(0, $show.val().length - 1));
            } else {
                $("#ce").trigger("click");
            }
        });
        var memory = [];


        $(document).on('click', 'button.function', function () {
            var addnum = $show.val();
            if (addnum) memory.push(addnum);
            $show.val($(this).val());
        });

        $('#equ').click(function () {


            var addnum = $show.val();
            memory.push(addnum);


            $.post("calculation.php", {
                execute: memory
            }, function (data, status) {
                console.log("Success!!");
                console.log(data);
                console.log(status);
            $show.val(data);
            var e = memory.join('');
            memory = [];
            });
        });
    });

php

<?php
if(isset($_POST['execute']) && is_array($_POST['execute'])) {
    $total = (int)$_POST['execute'][0];
    for($i=1;$i<count($_POST['execute']);$i+=2){
        switch($_POST['execute'][$i]){
            case '+': $total += (int)$_POST['execute'][$i+1];break;
            case '-': $total -= (int)$_POST['execute'][$i+1];break;
            default : $total += (int)$_POST['execute'][$i+1];
        }
    }
    echo $total;
}
else echo 'Error';
?>
  • 写回答

2条回答 默认 最新

  • douao2000 2014-12-15 01:31
    关注

    You should try

    echo json_encode($total);
    

    instead of

    echo $total;
    
    评论

报告相同问题?

悬赏问题

  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP