php获取angularjs,php-在angularjs的$_POST变量中获取数据

我尝试了链接中给出的相同示例,但数据以JSON格式发布.我想要$_POST变量中的数据.我怎么做?

这是我的代码:

search.js

function SearchCtrl($scope, $http) {

$scope.url = 'php/search.php'; // The url of our search

// The function that will be executed on button click (ng-click="search()")

$scope.search = function() {

// Create the http post request

// the data holds the keywords

// The request is a JSON request. i want the data in $_POST

$http.post($scope.url, { "data" : $scope.keywords}).

success(function(data, status) {

$scope.status = status;

$scope.data = data;

$scope.result = data; // Show result from server in our

 element 
 

}).

error(function(data, status) {

$scope.data = data || "Request failed";

$scope.status = status;

});

};

}

search.php

// The request is a JSON request.

// We must read the input.

// $_POST or $_GET will not work! **but i want it to work!**

$data = file_get_contents("php://input");

$objData = json_decode($data);

// perform query or whatever you wish, sample:

include 'connect.php';

mysql_select_db($database,$con);

$query = 'SELECT * FROM `product`';

$result = mysql_query($query) OR die(mysql_error());

$cnt = 0;

while ($row = mysql_fetch_assoc($result)) {

$nm = $row['name'];

//print_r($nm.' ');

if($objData->data == $nm) {

$cnt++;

}

}

if($cnt == 0) {

echo ' Sorry, no match!';

}

else {

echo ' I have found what you\'re looking for!';

}

我该如何解决?

解决方法:

只是普通的PHP:

$_POST['title'] or $_POST['content'];

你能行的

标签:angularjs,php

来源: https://codeday.me/bug/20191127/2076505.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值