TypeError: document.forms.loginForm is undefined
JS脚本
function login() {
Ext.Ajax.request({
url:"loginJson.jsp",
jsonData:createJson(),
callback:function(options,success,response){
if(success){
alert(response.responseText);
}
}
});
}
function createJson() {
//获得表单参数
var uname = document.forms["loginForm"].username.value;
var pw = document.forms["loginForm"].password.value;
var JsonObject = {
username : uname,
password : pw
};
return JsonObject;
}
JSP
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@page import="org.dom4j.io.*"%>
<%@page import=org.dom4j.* %>
<%@page import=java.io.* %>
<%@page import=net.sf.json.* %>
<%
BufferedReader in = request.getReader();
StringBuffer jsonStr = new StringBuffer();
String str = "";
while((str = in.readLine())!=null){
jsonStr.append(str);
}
JSONObject jsonObject = JSONObject.fromObject(jsonStr.toString());
String username = jsonObject.getString("username");
String password = jsonObject.getString("password");
String msg = "";
if("xu".equals(username) && "123".equals(password)){
msg = "OK";
}else{
msg = "GUN";
}
response.getWriter().write(msg);
%>
网页
<form id="loginFrom">
用户名:<input type="text" name="username"/><br />
密码:<input type="password" name="password"/><br />
<input type="button" value="提交表单" onclick="login()"/><br />
</form>
var uname = document.forms["loginForm"].username.value; 不明白这里为什么会错 脚本
[解决办法]
晕死
<form id="loginFrom">
和
document.forms["loginForm"]
仔细看区别。。。