Ext 表单提交时怎么总是提示值未定义啊,都调了一下午了

luoluojin 2009-04-03 12:48:05
html 页
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="login.aspx.cs" Inherits="login" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<link href="css/StyleSheet.css" rel="stylesheet" type="text/css" />
<link href="ext/resources/css/ext-all.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="ext/adapter/ext/ext-base.js"></script>
<script type="text/javascript" src="ext/ext-all.js"></script>
</head>
<body>
<form id="form1" runat="server">
<div>
<script>
Ext.QuickTips.init();
LoginWindow=Ext.extend(Ext.Window,{
title : '登陆系统',
width : 265,
height : 170,
collapsible : true,
defaults : {
border : false
},
buttonAlign : 'center',
createFormPanel :function() {
return new Ext.form.FormPanel( {
bodyStyle : 'padding-top:6px',
defaultType : 'textfield',
labelAlign : 'right',
labelWidth : 55,
labelPad : 0,
frame : true,
defaults : {
allowBlank : false,
width : 158
},
items : [{
cls : 'user',
name : 'username',
fieldLabel : '帐号',
blankText : '帐号不能为空'
}, {
cls : 'key',
name : 'password',
fieldLabel : '密码',
blankText : '密码不能为空',
inputType : 'password'
}, {
cls : 'key',
name:'randCode',
id:'randCode',
fieldLabel:'验证码',
width:80,
blankText : '验证码不能为空'
}]
});
},
login:function() {
this.fp.form.submit({
waitMsg : '正在登录......',
url : 'login.ashx?cmd=login',
success : function(form, action) {
//alert(action.response.responseText)
//window.location.href = 'default.aspx';
},
failure : function(form, action) {
form.reset();
if (action.failureType == Ext.form.Action.SERVER_INVALID)
Ext.MessageBox.alert('警告', action.result.errors.msg);
}
});
},
initComponent : function(){

LoginWindow.superclass.initComponent.call(this);
this.fp=this.createFormPanel();
this.add(this.fp);
this.addButton('登陆',this.login,this);
this.addButton('重置', function(){this.fp.form.reset();},this);

}
});

Ext.onReady(function()
{
var win=new LoginWindow();

win.show();
var bd = Ext.getDom('randCode');
var bd2 = Ext.get(bd.parentNode);
bd2.createChild({tag: 'img', src: 'checkcode.aspx',align:'absbottom'});
}
);
</script>


</div>
</form>
</body>
</html>

login.ashx 后台代码:
<%@ WebHandler Language="C#" Class="login" %>

using System;
using System.Web;

public class login : IHttpHandler {

public void ProcessRequest (HttpContext context) {
string cmd = context.Request["cmd"];
if (cmd == "login")
{
context.Response.Write("success");
}
}

public bool IsReusable {
get {
return false;
}
}

}

请高手帮我看是什么问题,我一提交就有脚本错误:

行: 24

字符: 1519

错误: 'success' 未定义

代码: 0

URL: http://localhost:3760/Ext_Demo/login.aspx

在线等
...全文
811 11 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
liujunvy89 2010-06-12
  • 打赏
  • 举报
回复
请问下那个朋友见过
消息: '0.manager.zseed' 为空或不是对象
行: 14
字符: 19891
代码: 0
URI: http://www.wibstar.com/orient/scripts/ext/ext-all.js
this.findParentByType('window').destroy();
第二次就报错 后面的操作执行不了 急死了
HNsnopy 2009-05-15
  • 打赏
  • 举报
回复
context.Response.Write("success");


修改成

context.Response.Write("{success:true}");试试看
  • 打赏
  • 举报
回复
  if (cmd == "login") 
{
context.Response.Write("{success:true}");
}
}
witcheryne 2009-05-14
  • 打赏
  • 举报
回复
这个是我前一项写的关于Ext JS 表单提交的文章,应该会对楼主有用...
http://witcheryne.javaeye.com/blog/335577

我当时也是调了一下午,没崩溃死... 还好最后把问题解决了...
枯木逢春雨 2009-05-13
  • 打赏
  • 举报
回复
context.Response.Write("{success:true}");
即可。
leadergg 2009-04-13
  • 打赏
  • 举报
回复
是后台没有接受到参数还是后台往前台返数据时出错?
Ghost_520 2009-04-07
  • 打赏
  • 举报
回复

我写出我提交表单的例子,你对比一下。


<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>华中电力科技开发公司电网事业二部短信群发平台</title>

</head>
<body background="images/webroot/login_backgroud.jpg">
<link rel="stylesheet" type="text/css" href="resources/css/ext-all.css" />
<script type="text/javascript" src="scripts/ext/ext-base.js"></script>
<script type="text/javascript" src="scripts/ext/ext-all.js"></script>

<script>
// sets default ExtJS blank image
Ext.BLANK_IMAGE_URL = "resources/images/default/s.gif";
Ext.QuickTips.init();
Ext.state.Manager.setProvider(new Ext.state.CookieProvider());

Ext.onReady(function(){
formWindow = new Ext.Window({
id:'formWindow',
title:'用户登录',
layout :"fit",
closable : false, // 禁止关闭登录页面
draggable : false, // 设置页被面不能拖动
resizable:false, // 不能拖动其大小
width:330,
height : 145,
items:[
new Ext.form.FormPanel({
id:'formTest',
// url:"index.jsp",
bodyStyle:'padding:10px',
border:false,
labelWidth:70,

items:[
new Ext.form.TextField({
id:'userName',
fieldLabel:'用户名',
//autoWidth: true,
width : 200,
allowBlank :false,
autoHeight: true
}),
new Ext.form.TextField({
id:'userPwd',
fieldLabel:'密码',
// autoWidth: true,
width : 200,
autoHeight: true,
allowBlank :false,
inputType:'password'
// vtype:'email' //设定此文本框输入的格式为 email 的格式
})],
buttons:[
new Ext.Button({
text:'登录',
type:'submit',
onSubmit : Ext.emptyFn,
listeners:{
click:function(){
if(formTest.getForm().isValid()){
Ext.MessageBox.show({
id : "refBox1",
title: '提示',
msg: '正在初始化,请稍后...',
progressText: 'Initialization...',
width : 300,
wait:true,
waitConfig: {interval:200}
});

setTimeout(function(){
Ext.MessageBox.hide();
Ext.example.msg('Done', 'Done Refresh!');
},50000);

// 实现AJAX提交表单
formTest.form.doAction('submit',{
url:'<%=path%>/login.do',
method:'post',

// 根据回调的 json 数据判断是 success 还是 failure
success:function(form,action){
document.location='index.jsp';
},
//提交失败的回调函数
failure:function(){
Ext.Msg.alert('错误','服务器出现错误请稍后再试!');
}
})
}
}
}
}),
new Ext.Button({
text:'取消',
type:'reset',
listeners:{
click:function(){formTest.form.reset()}
}
})
]
})],

contentEl:'formWindowEl'
});
})

</script>

<div class="x-hide-display" id="formWindowEl"></div>


<script>
Ext.onReady(function(){
try {
formWindow = Ext.getCmp('formWindow');
formTest = Ext.getCmp('formTest');
} catch(e){};
});
</script>
<script>
Ext.onReady(function(){

formWindow.show();

});
</script>
</body>
</html>
DWilliam 2009-04-07
  • 打赏
  • 举报
回复
(1)自定义信息:
success:function(result,request){
var info = request.result.msg;
......

后台:Response.Write("{success:true,msg:'" + msg + "'}");

(2)固定信息,function中的参数可以去掉。
luoluojin 2009-04-03
  • 打赏
  • 举报
回复
不是这个问题,我刚照你的做了,提交表单时还是一样表这个错
mumu_java 2009-04-03
  • 打赏
  • 举报
回复

Ext.onReady(function()
{
Ext.QuickTips.init();
LoginWindow=Ext.extend(Ext.Window,{
title : '登陆系统',
width : 265,
height : 170,
collapsible : true,
defaults : {
border : false
},
buttonAlign : 'center',
createFormPanel :function() {
return new Ext.form.FormPanel( {
bodyStyle : 'padding-top:6px',
defaultType : 'textfield',
labelAlign : 'right',
labelWidth : 55,
labelPad : 0,
frame : true,
defaults : {
allowBlank : false,
width : 158
},
items : [{
cls : 'user',
name : 'username',
fieldLabel : '帐号',
blankText : '帐号不能为空'
}, {
cls : 'key',
name : 'password',
fieldLabel : '密码',
blankText : '密码不能为空',
inputType : 'password'
}, {
cls : 'key',
name:'randCode',
id:'randCode',
fieldLabel:'验证码',
width:80,
blankText : '验证码不能为空'
}]
});
},
login:function() {
this.fp.form.submit({
waitMsg : '正在登录......',
url : 'login.ashx?cmd=login',
success : function(form, action) {
//alert(action.response.responseText)
//window.location.href = 'default.aspx';
},
failure : function(form, action) {
form.reset();
if (action.failureType == Ext.form.Action.SERVER_INVALID)
Ext.MessageBox.alert('警告', action.result.errors.msg);
}
});
},
initComponent : function(){

LoginWindow.superclass.initComponent.call(this);
this.fp=this.createFormPanel();
this.add(this.fp);
this.addButton('登陆',this.login,this);
this.addButton('重置', function(){this.fp.form.reset();},this);

}
});

var win=new LoginWindow();

win.show();
var bd = Ext.getDom('randCode');
var bd2 = Ext.get(bd.parentNode);
bd2.createChild({tag: 'img', src: 'checkcode.aspx',align:'absbottom'});
}
);


lz在做ext开发是要把ext代码放到Ext.onReady里边。

52,792

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 Ajax
社区管理员
  • Ajax
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧