Angular$http.post谷歌地图Javascript API错误
在使用Angular JSAngular$http.post谷歌地图Javascript API错误,javascript,angularjs,ajax,google-maps,Javascript,Angularjs,Ajax,Google Maps,在使用Angular JS$http.post()时,我发现Google Maps Javascript API有问题,在进行任何其他解释之前,以下是错误: angular.js:13642 TypeError: Cannot read property 'lat' of undefined at _.H.toString (js?key=API_KEY&libraries=places:97) at e (jquery.min.js:4)
$http.post()
时,我发现Google Maps Javascript API有问题,在进行任何其他解释之前,以下是错误:
angular.js:13642
TypeError: Cannot read property 'lat' of undefined
at _.H.toString (js?key=API_KEY&libraries=places:97)
at e (jquery.min.js:4)
at dc (jquery.min.js:4)
at dc (jquery.min.js:4)
at dc (jquery.min.js:4)
at dc (jquery.min.js:4)
at dc (jquery.min.js:4)
at Object.<anonymous> (jquery.min.js:4)
at Function.each (jquery.min.js:2)
at dc (jquery.min.js:4)
这是HTML
部分:
<section id="registra-membro" ng-controller="sostenitori as st">
<form novalidate method="post" name="st_f" id="add-sostenitori" ng-submit="st.validateSost(st_f)" ng-show="!st._posting">
...
<input type="text" autocomplete="off" ng-change="st.addLocation(sost)" g-places-autocomplete force-selection="true" ng-model="sost.luogo" name="lu_{{$index}}" class="col-2-3" placeholder="Indirizzo" required/>
</form>
</section>
这实际上是给我带来错误的部分,但我找不到它在哪里调用这个.H.prototype.toString
函数。H
应该是几何体。位置
部分,它有lat
和lng
等提供位置坐标的方法
另一个更新
我在googlemapsapi Javascript
中找到了我的angular
代码的哪一部分触发了该函数,它是这样的:
app.config(function ($httpProvider) {
$httpProvider.interceptors.push('httpInterceptor');
$httpProvider.defaults.transformRequest = function (data) {
if (data === undefined) {
return data;
}
console.log($.param(data));
return data;
};
$httpProvider.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded; charset=UTF-8';
});
$.param(data)
触发了错误,我想这是向前迈出的一大步:)在完全卡住一天后,我解决了我的问题。在
谷歌地图API Javascript
中搜索数小时后,我发现问题出在jQuery
函数上,该函数是$.param()
我不知道它为什么会触发错误(如前所述),但更改它消除了我的问题,所以,这就是我所做的 app.js
app.config(function ($httpProvider) {
$httpProvider.interceptors.push('httpInterceptor');
$httpProvider.defaults.transformRequest = function (data) {
if (data === undefined) {
return data;
}
// !! REMOVED $.param(data)
return data;
};
$httpProvider.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded; charset=UTF-8';
});
// Added $httpParamSerializerJQLike in dependencies
$http.post(php_data.ajax_url, $httpParamSerializerJQLike(send_data), {
headers: {
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
}
}).then(function (response) {
var data = response;
if (data.hasOwnProperty('status')) {
_sost._posting = false;
_sost._postresult = data.status;
if (data.status == 0) {
_sost._inserted = _completed.length;
}
}
_sost.lista = [{}];
});
因此,基本上,我用另一个
AngularJS
内置函数替换了jQuery.param()
函数,找到了对未来读者来说重要的内容,请指定您使用的版本,jQuery和Angular@KirillSlatin当然,我现在要补充我的问题:)您是否尝试过使用JSON.stringify(数据)而不是$.param(数据)?
app.config(function ($httpProvider) {
$httpProvider.interceptors.push('httpInterceptor');
$httpProvider.defaults.transformRequest = function (data) {
if (data === undefined) {
return data;
}
console.log($.param(data));
return data;
};
$httpProvider.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded; charset=UTF-8';
});
app.config(function ($httpProvider) {
$httpProvider.interceptors.push('httpInterceptor');
$httpProvider.defaults.transformRequest = function (data) {
if (data === undefined) {
return data;
}
// !! REMOVED $.param(data)
return data;
};
$httpProvider.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded; charset=UTF-8';
});
// Added $httpParamSerializerJQLike in dependencies
$http.post(php_data.ajax_url, $httpParamSerializerJQLike(send_data), {
headers: {
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
}
}).then(function (response) {
var data = response;
if (data.hasOwnProperty('status')) {
_sost._posting = false;
_sost._postresult = data.status;
if (data.status == 0) {
_sost._inserted = _completed.length;
}
}
_sost.lista = [{}];
});