0
$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');
  })
}

Getting this error in console:

TypeError: Cannot read property 'param' of undefined

Here is my Backend code which is written in PHP and I have checked with postman and data is fetching in 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);

After changing :

var data = {
id: arg
  };

Getting Empty data

enter image description here

Chit
  • 293
  • 2
  • 12

1 Answers1

0

You don't have to use it like this.

var data = $.param({
    id: arg
});

The data variable can just be an Object Literal like so.

var data = {
    id: arg
};
holydragon
  • 6,158
  • 6
  • 39
  • 62