我試圖使$ http.post調用api端點(http://developer.zoopla.com/docs/read/Arrange_Appraisals),但我得到一些選項錯誤。我試圖通過傳遞url來獲得請求中的參數,也嘗試通過傳遞一個對象作爲第二個參數。我在這裏創建了一個Plunker(http://plnkr.co/edit/0W1egx30DeCNwhC8OdSo?p=preview),請告知哪個是正確的方法以及導致錯誤的原因。
angular.module('someApp',[])
.controller('someCtrl',function($scope,$http){
$scope.data = {
branchId : 49953,
propertyId : 5646166,
custName : 'Joe',
custEmail : '[email protected]',
custNumber : '07978765543',
custNumberType : 'mobile',
custTime : 'anytime',
custMessage : 'some random message',
custEnquiryType : 'arrange_valuation',
api_key : 'Please look in plunker attached'
}
$scope.url = 'http://api.zoopla.co.uk/api/v1/arrange_appraisal.js'
$scope.postData = function(){
alert('Please check console for error')
$http.post($scope.url,$scope.data)
.success(function(res){
console.log(res)
})
.error(function(err){
console.log(err)
})
}
$scope.postData2 = function(){
alert('Please check console for error')
$http.post('http://api.zoopla.co.uk/api/v1/arrange_appraisal.json?branch_id=18269&property_id=5646170&name=somename&[email protected]&phone=07476566718&phone_type=mobile&best_time_to_call=afternoon&message=hello&type_of_enquiry=looking_to_sell&api_key=pleaseCheckPlunker')
.success(function(res){
console.log(res)
})
.error(function(err){
console.log(err)
})
}
})
o是啊是啊是啊...缺少逗號..我試試.. :) –
只是更新了搶劫但仍然問題=> http://plnkr.co/edit/0W1egx30DeCNwhC8OdSo?p=preview –