Javascript 并非所有数据都使用$http.post angularjs发送
为什么每当我从移动应用程序(Ionic Framework)向服务器发送数据时,并不是所有的数据都被发送Javascript 并非所有数据都使用$http.post angularjs发送,javascript,angularjs,Javascript,Angularjs,为什么每当我从移动应用程序(Ionic Framework)向服务器发送数据时,并不是所有的数据都被发送 $http({ method: 'POST', url: 'http://remoteserver/data', headers: {'Content-Type': 'application/x-www-form-urlencoded'}, transformReq
$http({
method: 'POST',
url: 'http://remoteserver/data',
headers: {'Content-Type': 'application/x-www-form-urlencoded'},
transformRequest: function(obj) {
var str = [];
for(var p in obj)
str.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p]));
return str.join("&");
},
data: { image: $scope.imgURI,
facebook_id: localStorage.facebook_id,
token: localStorage.accessToken,
location: localStorage.location,
lon: localStorage.longitude,
lat: localStorage.latitude
}
}).success(function (suc)
{
localStorage.removeItem('longitude');
localStorage.removeItem('latitude');
localStorage.removeItem('location');
alert(JSON.stringify(suc));
})
.error(function(err){alert(JSON.stringify(err));});
服务器收到后,位置
未定义。事实上,我提醒它检查它是否为空。我怎样才能解决这个问题?在发送到我的服务器的所有数据中,只有位置丢失。位置是纬度和经度的反向地理编码。我只是把它放在我的手机里,以减少谷歌API的过度使用,因为它是基于会话的
在我的服务器上(使用laravel),我使用
$post->lon = Input::get('lon');
$post->lat = Input::get('lat');
$post->location = Input::get('location');
$post->token= Input::get('token');
$post->facebook_id = Input::get('facebook_id');
当我试图
返回Input::all()时代码>我看到除位置之外的所有发送数据。它说未定义。问题是,我可以获取一次位置,在我再次尝试后,它返回未定义。为什么你认为是angularjs造成的?您确定发送前的数据是您期望的数据吗?你怎么知道的?你检查过了吗?如何?如果您不显示服务器代码,我们如何知道服务器为什么不发送回位置是的,因为我使用$post->varible=Input::get('variable')
来获取位置,我还将其用于其他位置,如纬度和经度。除了位置,我都知道了。顺便说一句,我在后端使用laravel。由于错误在服务器端,如果需要帮助,请提供更多代码。我已经解决了这个问题。我把它放在服务器上,而不是客户端。因此,我的服务器将是访问API的服务器。不过,这样做的缺点是,我会限制API调用,因为服务器端调用是基于IP的,不像客户端,而是基于每个用户会话