我已经在数据库中获取了我的经度和经度值,并试图通过单击具有id(“ track”)的按钮将其获取到我的javascript中。但是以下代码引发了在未实现接口HTMLInputElement的对象上调用的“ stepUp”错误。该如何解决
提前感谢。
Create.js
document.getElementById("track").onclick=function tracking(){
console.log("Tracking");
var tname=document.getElementsByName("frname");
var params ={
trname:tname,
bt:"I"
}
$.get("SC",$.param(params),function(responsetext){
var a=responsetext;
console.log(a);
});
}
ServerConnect.java
if(bt1.equals("I")){
String tname=request.getParameter("tname");
String uname=(String)session.getAttribute("uname");
try {
cords =requestingclass.getupdatedlocation(tname,uname);
String lat=cords.get(1);
String lng=cords.get(2);
response.setContentType("text/plain");
response.setCharacterEncoding("UTF-8");
response.getWriter().write(lat);
response.getWriter().write(lng);
} catch (ClassNotFoundException | SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
requestingclass.java
public static ArrayList<String> getupdatedlocation(String tname, String uname) throws ClassNotFoundException, SQLException {
Connection con = ConnectionUtility.connect();
PreparedStatement ps =con.prepareStatement("select lat,lng from requesttable where requester=? and requested=?");
ps.setString(1, uname);
ps.setString(2, tname);
ArrayList<String> cords=null;
ResultSet rs= ps.executeQuery();
while(rs.next()){
cords=new ArrayList<String>();
cords.add(rs.getString(1));
cords.add(rs.getString(2));
}
return cords;
}
这是导致问题的行:
var tname = document.getElementsByName("frname");
tname
保存一个Element对象。然后,您尝试将其发送到请求的数据中,因此jQuery尝试对其进行序列化,从而导致问题。
我从上下文中假定您希望获取元素的值,因此请改用此:
var tname = document.getElementsByName("frname").value;