【发布时间】:2019-04-22 18:07:27
【问题描述】:
$scope.productDetails = {};
$scope.getProductDetailById = function(arg) {
var data = $.param({
id: arg
});
$http({
method: 'POST',
url: 'http://' + $scope.url + '/scripts/viewProductById.php',
headers: {
'Content-Type': 'application/x-www-form-urlencoded;'
},
data: data
})
.then(function(response) {
$scope.productDetails = response.data;
$location.path('/single_product');
},
function(response) {
//alert('wrong');
})
}
在控制台中出现此错误:
TypeError: 无法读取未定义的属性“参数”
这是我用 PHP 编写的后端代码,我已经与邮递员核对过,数据正在 json 中获取:
session_start();
require 'db.php';
$id = $_POST['id'];
$sql = "SELECT * FROM product WHERE id='$id'";
$qur = $connection->query($sql);
$r = mysqli_fetch_assoc($qur);
$msg[] = array("id" => $r['id'],"name" => $r['name'],"category" => $r['category'],"material" => $r['material'],
"pattern" => $r['pattern'],"occasion" => $r['occasion'],"length" => $r['length'],"width" => $r['width'],
"wash_care" => $r['wash_care'],"color" => $r['color'],"stock" => $r['stock'],"new_price" => $r['new_price'],
"old_price" => $r['old_price'],"delivery_in" => $r['delivery_in'],"image_one" => $r['image_one'],
"image_two" => $r['image_two'],"image_three" => $r['image_three'],"image_four" => $r['image_four'],
"image_five" => $r['image_five'],"description" => $r['description'],"date" => $r['date']);
$json = $msg;
header('content-type: application/json');
echo json_encode($json);
@mysqli_close($connection);
更改后:
var data = {
id: arg
};
获取空数据
【问题讨论】:
-
param是$的一个属性,它是未定义的。$是什么? jQuery?你有它的脚本吗? -
不,只是我使用了 jquery 库和 angular.min.js
-
我调用了很多函数,但只有这个函数我得到了这样的结果。
-
你不能直接打电话给
$http.post('http://'+ $scope.url +'/scripts/viewProductById.php', { id:arg })吗? -
但在我的管理仪表板项目中使用相同的代码