[英]Uncaught ReferenceError: [function] is not defined
I'm trying to implement Googlemaps in my Page but i'm getting into some problems surly because I'm still new with webdev. 我正在尝试在自己的Page中实现Googlemaps,但是由于Webdev仍然很陌生,所以我遇到了一些麻烦。
I've followed the google API tutorial on saving data to a database and created the appropriate functions in my .js file. 我遵循了有关将数据保存到数据库的google API教程,并在.js文件中创建了相应的函数。
The code looks like this: 代码如下:
function createMarker(location){
if(poiMode && activeMarkerIcon != null) {
var marker = new google.maps.Marker({
position: location,
icon: activeMarkerIcon,
clickable:true,
draggable:true,
animation:null,
raiseOnDrag:false,
title: Titel,
map: map
});
useFilter();
activeGroup.push(marker); // Marker wird zum dazugehörigenArray hinzugefuegt
map.setOptions({draggableCursor:'default'}) // Mauscursor wieder in ursprünglichen Zustand versetzen
$('body, #poi1, #poi2, #poi3, #poi4, #poi5, #poi6, #poi7, #loeschen').removeClass('poi1A poi2A poi3A poi4A poi5A poi6A poi7A deleteA');
var html = "<table>" +
"<tr><td>Name:</td> <td><input type='text' id='name'/> </td> </tr>" +
"<tr><td>Beschreibung:</td> <td><TEXTAREA id='description' rows='10' cols='50'></TEXTAREA></td> </tr>" +
"<tr align='right'><td></td><td><input type='button' value='Speichern' onclick='saveData()'/></td> <td><input type='button' value='Abbrechen' onclick='infowindow.close()'/></td> </tr>";
infowindow = new google.maps.InfoWindow({
content: html
});
poiMode = false;
infowindow.open(map, marker);
google.maps.event.addListener(marker, 'click', function(event){
clickOnMarker(marker);
});
$('.activeButton').removeClass("activeButton");
}
}
and the saveData() function is in the same .js file and looks like this: 而saveData()函数位于相同的.js文件中,如下所示:
function saveData() {
var name = escape(document.getElementById("name").value);
var address = escape(document.getElementById("address").value);
var latlng = marker.getPosition();
var url = base_url + "map/addMarker?name=" + name + "&address=" + address + "&description=" + "test" + "&user_id=" + "1" +"&lat=" + latlng.lat() + "&lng=" + latlng.lng() + "&date=" + "" +"&type=" + "poi";
downloadUrl(url, function(data, responseCode) {
if (responseCode == 200 && data.length <= 1) {
infowindow.close();
document.getElementById("message").innerHTML = "Location added.";
}
});
}
Yet when I press the save Button on my "Form" I get the console error: 但是,当我按“表单”上的保存按钮时,出现控制台错误:
Uncaught ReferenceError: saveData is not defined 未捕获的ReferenceError:未定义saveData
Could you please tell me, what I'm doing wrong? 你能告诉我,我做错了吗? since I cant see my own error. 因为我看不到自己的错误。 Thanks in Advance 提前致谢
I've resolved this issue by defining saveData()
as a function of infowindow 我已通过将saveData()
定义为saveData()
的函数解决了此问题
infowindow.saveData = function(){
...
});
and calling the function with: 并使用以下命令调用该函数:
<input type='button' value='Save' onclick='infowindow.saveData()'/>
Thanks basilikum and everyone else! 感谢baslikumum和其他所有人!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.