简体   繁体   English

如何从表单获取值并使用javascript将其发送到Java类?

[英]How to get values from a form and send it to Java class using javascript?

First i have declare that i am new to javascript. 首先,我宣布我是javascript新手。 I have created a form that gets Id, Name, Age & Dept. I want it to send to java class and i have to show back the data along with the other data in the data Base using DWR. 我创建了一个形式获取ID,姓名,年龄及部,我希望它发送到java类,我必须在使用DWR 数据库中的其他数据显示回数据。

For this i already done coding for showing the table, below that i have my form. 为此,我已经完成了显示表格的编码,在此下方有我的表格。 After the form "Save" button calls the below function save(). 在“保存”按钮之后,调用以下函数save()。 Here, my form and function. 在这里,我的形式和功能。

The Form: 表格:

Id:<input type="text" id="id"/><br>
Name:<input type="text" id="name"/><br>
Age:<input type="text" id="age"/><br>
Dept:<input type="text" id="dept"/><br>
<input id="Save" type="button" value="Save" onclick="save()"/>

The function: 功能:

function save(){
employee = new Object();
employee.id = dwr.util.getValue(iD);
employee.name = dwr.util.getValue(namE);
employee.age = dwr.util.getValue(agE);
employee.dept = dwr.util.getValue(depT);

dwr.engine.beginBatch();
Employee.aouEmployee(employee);  //   **Java method call to store data in DB**
fetch();//An another function which loads all the data in the table.
dwr.engine.endBatch();
}

But, i cant get proper output for the above function. 但是,我无法获得上述功能的正确输出。 I am also cant able to find the mistakes(due to no error msgs) 我也无法找到错误(由于没有错误消息)

Any suggestions will be more appreciative 任何建议都会更感激

Thanks 谢谢

UPDATES ARE HIGHLIGHTED BY BOLD 突出显示了更新

  1. Install Firefox, if you haven't already 如果尚未安装Firefox,请安装
  2. Install Firebug 安装Firebug
  3. Use Firebug to debug JS, as well as its Net panel to debug AJAX calls; 使用Firebug调试JS,以及使用其Net面板调试AJAX调用; use console.log(string) to get feedback 使用console.log(string)获得反馈
  4. Profit. 利润。

By the way, for my curiosity: what's up with capitalising the last letter in a variable? 顺便说一句,出于我的好奇心:将变量中的最后一个字母大写怎么办?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM