如何调用与此jquery等价的http post
在我的Rest.In.php中如何调用与此jquery等价的http post,jquery,angularjs,Jquery,Angularjs,在我的Rest.In.php中 private function set_headers(){ header("HTTP/1.1 ".$this->_code." ".$this->get_status_message()); header("Content-Type:".$this->_content_type); } 我使用jquery并得到了响应 <script> $(document).ready(f
private function set_headers(){
header("HTTP/1.1 ".$this->_code." ".$this->get_status_message());
header("Content-Type:".$this->_content_type);
}
我使用jquery并得到了响应
<script>
$(document).ready(function(){
$("button").click(function(){
alert("haha");
$.post("http://localhost/fudline/access/hotels/loadplaces",
{
district: "Malappuram"
},
function(data,status){
alert(data);
console.log(data);
console.log(status);
});
});
});
</script>
$(文档).ready(函数(){
$(“按钮”)。单击(函数(){
警惕(“哈哈”);
$.post(”http://localhost/fudline/access/hotels/loadplaces",
{
地区:“马拉普兰”
},
功能(数据、状态){
警报(数据);
控制台日志(数据);
控制台日志(状态);
});
});
});
如何为此调用angular http post…我尝试了下面的代码,但没有使用success()函数..我需要使用angular js,因为我想使用ng repeat
<script>
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope, $http) {
$scope.loadPlace = function(x) {
alert(x);
$http({
method: 'POST',
url: 'http://localhost/fudline/access/hotels/loadplaces',
data: { district: "Malappuram"},
headers: {'Content-Type': 'application/x-www-form-urlencoded'}
})
.success(function(data, status, headers, config) {
alert("haha");
alert(data);
$scope.places = data;
}).error(function(data, status, headers, config) {
//
});
}
</script>
var-app=angular.module('myApp',[]);
app.controller('myCtrl',函数($scope,$http){
$scope.loadPlace=函数(x){
警报(x);
$http({
方法:“POST”,
网址:'http://localhost/fudline/access/hotels/loadplaces',
数据:{地区:“马拉普兰”},
标题:{'Content-Type':'application/x-www-form-urlencoded'}
})
.success(函数(数据、状态、标题、配置){
警惕(“哈哈”);
警报(数据);
$scope.places=数据;
}).error(函数(数据、状态、标题、配置){
//
});
}
您需要自己序列化数据,因为$http
默认值是序列化为json而不是URL编码,这是$的默认值。ajax
注入服务和更改:
data: { district: "Malappuram"},
到
data: $httpParamSerializerJQLike({ district: "Malappuram"}),