这是 Angular 代码。我喜欢这个删除功能代码。运行时出现这样的错误:
JSON Parse error: Unexpected identifier "Param"
$scope.delete = function(cart_ID, index) {
var params = $.param({"cart_ID":cart_ID});
console.log(cart_ID);
$http({
headers: {'Content-Type': 'application/x-www-form-urlencoded'},
url: 'http://localhost/test1/shopCartProductDelete.php?cart_ID'+ cart_ID,
method: "GET",
data: params
}).success(function(data){
$scope.data.splice(index, 1);
});
shopCartProductDelete.phpt
<?php
header("Access-Control-Allow-Origin: *");
header("Content-Type: application/json;charset=UTF-8");
$con = mysqli_connect("localhost","root","","look4com_lk");
if(isset($_GET['cart_ID'])){
$cart_ID = $_GET['cart_ID'];
$res = "DELETE FROM l4wlk_cart WHERE cart_ID='".$cart_ID."'";
mysqli_query($con, $res) or mysqli_error($con);
}else{
die("Param value not set up");
}
最佳答案
您的 jQuery AJAX 请求中缺少 =
(可能不相关,但您最好检查 $_GET['cart_ID']
实际上是通过 data
发送到您的 PHP 脚本的):
url: 'http://localhost/test1/shopCartProductDelete.php?cart_ID'+ cart_ID
应该是:
url: 'http://localhost/test1/shopCartProductDelete.php?cart_ID='+ cart_ID
现在,如果您尝试将其作为 json
使用,则需要发送 application/json
,而不是 text/plain
:
echo json_encode(['error' => true, 'message' => 'Param not set']);
关于javascript - 删除功能不起作用 像这样的错误 JSON 解析错误 : Unexpected identifier "Param",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39324580/