【发布时间】:2014-12-15 00:42:29
【问题描述】:
我正在尝试将一些数据发布到 php,但它无法正常工作,而且我已经检查了 chrome 开发工具。当我单击相等按钮时,它将出现此状态: 计算.php 方法:选项 状态:(取消) 文本/纯文本 jquery.min.js:4 0 B 8 毫秒
我不确定是什么问题。然而它在这里工作: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';
?>
【问题讨论】:
-
你确定你有某种网络服务器正在运行,比如 Apache(例如 xampp)?
-
我猜没有任何网络服务器在运行
-
因为 PHP 是一种服务器端语言,据我所知,您需要运行某种 PHP 服务器才能使用 PHP 进行任何操作。以 Apache 为例:apachefriends.org/index.html
-
你确定在 localhost 上调用了正确的 url 吗?
-
我不知道,因为我使用ajax发布到php
标签: javascript php jquery google-chrome