[英]I am trying to pass values from Database to js. But i am getting an error of stepup?
I have got my lat and lng values in database and trying to get them to my javascript on click of a button with id("track").我在数据库中得到了我的 lat 和 lng 值,并试图通过单击带有 id("track") 的按钮将它们发送到我的 javascript。 but the following code throws an error of "stepUp" called on an object that does not implement interface HTMLInputElement.
但是下面的代码会在未实现接口 HTMLInputElement 的对象上引发“stepUp”错误。 how to solve this
如何解决这个问题
Thanks in advance.提前致谢。
Create.js创建.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请求类.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;
}
It's this line causing the problem:这是导致问题的这一行:
var tname = document.getElementsByName("frname");
tname
holds an Element object. tname
包含一个 Element 对象。 You then attempt to send it in the data of the request, so jQuery tries to serialise it, causing the problem.然后您尝试将它发送到请求的数据中,因此 jQuery 尝试对其进行序列化,从而导致问题。
I presume from the context you instead want to get the value of the element, so use this instead:我从上下文中推测您想要获取元素的值,因此请改用它:
var tname = document.getElementsByName("frname").value;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.