枯木逢春雨 2009-05-13 09:40 采纳率: 33.3%
浏览 344
已采纳

EXT页面加载后台数据问题

我刚接触EXT,试做了一个页面,在页面打开时,加载后台取到一个ID值,显示在页面的“编号”文本输入框内,
大致代码如下:
[code="C#"]
loginForm = new Ext.form.FormPanel({
labelAlign: 'left', buttonAlign: 'center', bodyStyle: 'padding:5px',
frame: true, labelWidth: 80,
items: [
{
xtype: "textfield",
fieldLabel: "编号",
name: "ContactId"

}, {
xtype: "textfield",
fieldLabel: "工程名称",
name: "ProjectName",
allowBlank: false,
blankText: '请输入工程名称'
},
listeners:{
render:function(){
var jsonDataObj = loginForm .getForm().getValues();
Ext.Ajax.request({
url: 'GetMaxId.ashx',
params: '',
jsonData: jsonDataObj,
success: function(response, options) {
var responseData = Ext.decode(response.responseText);
loginForm.getForm().setValues(responseData)[
{ id: "ContactId", value: responseData.data.maxid }];
},
failure: function() {
Ext.Msg.alert('错误', '发生错误!');
}
})
}
})

[/code]

后台简易代码:
[code="C#"]
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
//省略逻辑处理
context.Response.Write("{success:true,data:{msg:'加载成功!',maxid:newMaxId}}");
}
[/code]

现在页面代码里的responseData取不到值,
response.responseText本身就没值,
而且后台返回staus都是failure,
请问我这个页面后台调用响应是不是有问题啊?!
有没有人能帮我解答一下?!谢谢
[b]问题补充:[/b]
取不到值的问题我是找到了,
context.Response.Write("{success:true,data:{msg:'加载成功!',maxid:newMaxId}}");

这话给绕了:
context.Response.Write("{success:true,data:{msg:'加载成功!',maxid:'" + newMaxId + "'}}");
一开始就被双引号引着,之前代码里得到的值没办法设回去了。

现在问题页面上是得到后台返回的值了,但不清楚应该怎么传给页面控件,

还有一个,我不是想通过按钮激发取值,我是想在页面加载时,去后台取值显示在页面上。

  • 写回答

2条回答 默认 最新

  • zhoujuan520 2009-05-13 17:20
    关注

    [img]http://yourgame.iteye.com/upload/picture/pic/36855/c637e19a-baed-329b-919b-fdbf2c5f1460.gif[/img]

    好久没有写c#了.基本上忘记了.
    我用jsp帮你写了一个,就是简单的从jsp页面里面输出json字符串而已

    从你的问题描述来看可以看出来你根本就没有访问到GetMaxId.ashx 这个页面,请注意路径的问题,如果直接进入failure就表示请求失败
    下面是我的代码,可以运行的.你看看.你把jsp页面里面的代码转成你的c#代码就可以了.两种语言是相通的!

    jsonAction.jsp
    [code="html"]
    <%@page contentType="text/html; charset=UTF-8"%>
    <%
    response.getWriter().write("{'success':true,'data':{'ProjectName' : '工程名','ContactId' : '12346','msg':'加载成功!','maxid':'newMaxId'}}");
    %>
    [/code]

    [code="js"]
    Ext.onReady(function() {
    var loginForm = new Ext.form.FormPanel({
    renderTo : document.body,
    labelAlign : 'left',
    buttonAlign : 'center',
    bodyStyle : 'padding:5px',
    frame : true,
    labelWidth : 80,
    items : [{
    xtype : "textfield",
    fieldLabel : "编号",
    name : "ContactId"
    }, {
    xtype : "textfield",
    fieldLabel : "工程名称",
    name : "ProjectName",
    allowBlank : false,
    blankText : '请输入工程名称'
    }],
    buttons : [{
    text : '取值',
    handler : function() {
    Ext.Ajax.request({
    url : 'jsonAction.jsp',
    success : function(response, options) {
    var responseData = Ext.decode(response.responseText);
    loginForm.getForm().setValues(responseData.data)
    alert(responseData.data.maxid);
    // [{ //不明白你这里为什么这么写?
    // id : "ContactId",
    // value : responseData.data.maxid
    // }];
    },
    failure : function() {
    Ext.Msg.alert('错误', '发生错误!');
    }
    })
    }
    }],
    listeners : {
    'render' : function() {
    // 你在这里捕捉渲染事件肯定是有问题的.因为你在这里取loginForm对象
    // 在渲染事件发生的时候loginForm对象都还不存在.
    }
    }
    });
    });

    [/code]

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?