简体   繁体   English

我正在尝试将值从数据库传递给 js。 但是我收到了一个步进错误?

[英]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.

相关问题 使用 Next js 时出现以下错误。 我正在使用 axios 作为 http 客户端构建身份验证管道 - I am getting the following error using Next js. I am building an authentication pipeline using axios as the http client 当我尝试在 JavaScript 中将变量从一个函数传递到另一个函数时,我收到 Reference Error: variable is not defined 错误(邮递员) - I am getting Reference Error: variable is not defined error when I am trying to pass variable from one function to another in JavaScript ( postman) 我正在尝试实施评级系统,但是我无法在Vue js中传递评级值? - I am trying to implement a rating system But I am not not able to pass the values of rating in Vue js? 我正在尝试从数据库中获取 map mydata 但我收到此错误。 TypeError:无法读取未定义的属性“地图” - I am trying to map mydata from the database but i am getting this error. TypeError: Cannot read property 'map' of undefined 我对 JS 中的循环有疑问。 我是新手 - I have a query about Loops in JS. I am a newbie 我正在尝试将一个值从 servlet 文件传递​​到 javascript 文件,但我一直为 null 我做错了什么? - I am trying to pass a value from servlet file to javascript file and i am keep getting null where am i doing wrong? 我正在尝试下载React js,但是又一次又一次出现此错误? - I am trying to download React js, but I am getting this error again and again? 我正在尝试将数据从 HTML 表单发送到 Google 表格,我收到访问错误 - I am trying to send data from HTML Form to Google Sheet , I am getting Access Error 我正在尝试使用js将多个功能和按钮连接在一起。 和html。 我不确定我缺少什么 - I am trying to connect multiple functions and buttons together using js. and html. and I'm not sure what i'm missing 为什么我收到这个JS错误? - Why am I getting this JS error?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM