extjs.Ajax.request与asp.net(C#)交互 调用extjs.Ajax.request与asp.net(C#)交互时老是执行failure function(),是什么原因啊?要怎么解决? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 查一下是不是超时了。或者asp.net 页面是否异常。 贴出代码:这是 index.aspx<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="index.aspx.cs" Inherits="asp_extjs.index" %><!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 id="Head1" runat="server"> <title>学生信息管理系统</title> <link rel="Stylesheet" type="text/css" href="ext-2.3.0/resources/css/ext-all.css" /> <link rel="Stylesheet" type="text/css" /> <link rel="Stylesheet" type="text/css" href="ext-2.3.0/resources/css/xtheme-slate.css" /> <script type="text/javascript" src="ext-2.3.0/adapter/ext/ext-base.js"></script> <script type="text/javascript" src="ext-2.3.0/ext-all.js"></script></head><body> <form id="form1" runat="server"> <div> <script type="text/javascript"> //界面设计函数 function LoginLayout() { //左边功能区 var fpanel = new Ext.form.FormPanel ({ region: "west", width: 200, title: "菜单", collapsible: true, //可隐藏 items: [ { xtype: "button", text: "添加信息", listeners: { "click": function() { contentPanel.setActiveTab("add"); } } }, //"添加信息"按钮 {xtype: "button", text: "删除信息", listeners: { "click": function() { contentPanel.setActiveTab("del"); } } }, //"删除信息"按钮 {xtype: "button", text: "查询信息", listeners: { "click": function() { contentPanel.setActiveTab("query"); } }} //"查询信息"按钮 ] }); //右边功能区:TabPanel var contentPanel = new Ext.TabPanel ({ region: "center", frame: true, bodyStyle: "background-color:#F80000; border-width: 0px 2px 0px 0px", enableTabScroll: true, activeTab: 0, items: [ //"添加信息"选项卡 {title: "添加信息", id: "add", layout: "form", defaultType: 'textfield', items: [ { fieldLabel: "请输入学号", id: "id" }, { fieldLabel: "请输入姓名", id: "name" }, { fieldLabel: "请输入年龄", id: "age" }, //性别选择 单选按钮 {xtype: 'panel', id: "sex", layout: 'table', border: false, fieldLabel: "请选择性别", defaultType: 'radio', isFormField: true, items: [ { id: "boy", boxLabel: "男", inputValue: "", name: "userSex", checked: true }, { id: "girl", boxLabel: "女", inputValue: "", name: "userSex" } ] }, //"添加"与"重置" 按钮 {xtype: 'panel', id: "buttons", width: 234, layout: 'table', isFormField: false, border: false, buttonAlign: "center", items: [ { xtype: "button", id: "btnAdd", text: "添加" ,handler:validatorData, listeners:{"click":function(){ Ext.Msg.alert("通知","执行数据库"); }} }, { xtype: "button", id: "btnreset", type: "reset", text: "重置",listeners:{ "click":function(){ Ext.getCmp("id").setValue("") ; Ext.getCmp("name").setValue("") ; Ext.getCmp("age").setValue("") ;} } } ] } ] }, { title: "删除信息", id: "del" }, { title: "查询信息", id: "query" } ] }); /////////整体界面 new Ext.Viewport ({ enableTabScroll: true, layout: "border", items: [ { title: "学生信息管理系统", region: "north", height: 100, html: "<center><h2>学生信息管理系统</h2></center>" }, fpanel, contentPanel ] }); }; ////////////////数据交互函数 function validatorData(){ var ID=Ext.getCmp("id").getValue(); var Name=Ext.getCmp("name").getValue(); var Age=Ext.getCmp("age").getValue(); var Sex="男";//Ext.getcmp("userSex").getGroupValue(); if(Ext.util.Format.trim(ID)==""||Ext.util.Format.trim(Name)==""||Ext.util.Format.trim(Age)==""){ Ext.Msg.alert("警告","请将信息填写完整!"); return; } Ext.Msg.alert("消息",ID+Name+Age+Sex); Ext.Ajax.request({ //请求的地址 url:'Default.aspx?parm=insert', method: 'POST', //发送的参数 params:{ParamValue:"1",ParamID:ID,ParamName:Name,ParamSex:Sex,ParamAge:Age}, //params:{ParamValue:"1",ParamUserName:UserName,ParamPassword:Password} success:function(response,option){ var obj=Ext.util.JSON.decode(response.responseText);//返回的信息 Ext.Msg.alert("好消息","储存成功!"); }, failure:function(){ Ext.Msg.alert("坏消息","存取异常!"); } }) } ///////////////////// function Login() { //界面设计函数 LoginLayout(); //validatorData(); } Ext.onReady(Login); </script> </div> </form></body></html>这是 Default.aspx<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="asp_extjs._Default" %>这是Default.aspx.csusing System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;using Service;//添加命名空间using System.Data.SqlClient;using System.Web.Script.Serialization;//Json序列化using System.Text;namespace asp_extjs{ public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { String ParamValue = Request.QueryString["parm"].ToString(); if (ParamValue == "insert") { String ID = Request.QueryString["ParamID"].ToString(); String Name = Request.QueryString["ParamName"].ToString(); String Age = Request.QueryString["ParamAge"].ToString(); String Sex = Request.QueryString["ParamSex"].ToString(); Console.Write(ID + Name + Age + Sex); Console.Out.WriteLine("开始插入!"); /////////////////////////// String sql = "insert into student values('" + ID + "','" + Name + "','" + Age + "'," + Sex + ")"; try { // int count = cmd.ExecuteNonQuery(); int count = Service.DBHelper.ExecuteCommand(sql); if (count != 0) { Response.Write("{success:true}"); } else { // Response.Write("{success:true}"); Response.Write("{success:false}"); } } catch (Exception) { throw; } } } }} 原来是win7中iis服务对asp.net设置问题,根源在validateData.cs 中数据库的访问出问题,不过我还没有解决这个问题 楼主能和我交流下吗,我的qq是372289475,我也遇到了这个问题,前面也是对的,后面也是对的,就是无法进行交互,每次访问数据库就选择failure 怎么在别人的网站上放自己后台发布的信息 求教,连接字符串中的Max Pool Size最大可设置为多少? ******求一个在线问卷调查的思路,多谢各位!!(里面有我的思路请指点)****** 关于分页问题 请教老师关于三层架构的问题 Datagrid控件的超级连接列可以带一个参数到下一个页面,方法URL格式字符串写:abc2.aspx?a1={0},问题是如何带两个参数到下一个页面? 新手问一个问题~~~~ 如何用Button?? 加盟NET开发团队! 一个数据库插入问题,大家帮忙看看 XML字符转换问题? aspx页在虚拟空间的问题
这是 index.aspx<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="index.aspx.cs" Inherits="asp_extjs.index" %><!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 id="Head1" runat="server">
<title>学生信息管理系统</title>
<link rel="Stylesheet" type="text/css" href="ext-2.3.0/resources/css/ext-all.css" />
<link rel="Stylesheet" type="text/css" />
<link rel="Stylesheet" type="text/css" href="ext-2.3.0/resources/css/xtheme-slate.css" />
<script type="text/javascript" src="ext-2.3.0/adapter/ext/ext-base.js"></script>
<script type="text/javascript" src="ext-2.3.0/ext-all.js"></script>
</head>
<body>
<form id="form1" runat="server">
<div>
<script type="text/javascript"> //界面设计函数
function LoginLayout()
{
//左边功能区
var fpanel = new Ext.form.FormPanel
({
region: "west",
width: 200,
title: "菜单",
collapsible: true, //可隐藏
items:
[
{ xtype: "button", text: "添加信息", listeners: { "click": function() { contentPanel.setActiveTab("add"); } } }, //"添加信息"按钮
{xtype: "button", text: "删除信息", listeners: { "click": function() { contentPanel.setActiveTab("del"); } } }, //"删除信息"按钮
{xtype: "button", text: "查询信息", listeners: { "click": function() { contentPanel.setActiveTab("query"); } }} //"查询信息"按钮
]
});
//右边功能区:TabPanel
var contentPanel = new Ext.TabPanel
({
region: "center",
frame: true,
bodyStyle: "background-color:#F80000; border-width: 0px 2px 0px 0px",
enableTabScroll: true,
activeTab: 0,
items:
[
//"添加信息"选项卡
{title: "添加信息", id: "add", layout: "form", defaultType: 'textfield',
items:
[
{ fieldLabel: "请输入学号", id: "id" },
{ fieldLabel: "请输入姓名", id: "name" },
{ fieldLabel: "请输入年龄", id: "age" },
//性别选择 单选按钮
{xtype: 'panel', id: "sex", layout: 'table', border: false, fieldLabel: "请选择性别", defaultType: 'radio', isFormField: true,
items:
[
{ id: "boy", boxLabel: "男", inputValue: "", name: "userSex", checked: true },
{ id: "girl", boxLabel: "女", inputValue: "", name: "userSex" }
]
},
//"添加"与"重置" 按钮
{xtype: 'panel', id: "buttons", width: 234, layout: 'table', isFormField: false, border: false, buttonAlign: "center",
items:
[
{ xtype: "button", id: "btnAdd", text: "添加" ,handler:validatorData,
listeners:{"click":function(){ Ext.Msg.alert("通知","执行数据库"); }}
},
{ xtype: "button", id: "btnreset", type: "reset", text: "重置",listeners:{ "click":function(){ Ext.getCmp("id").setValue("") ; Ext.getCmp("name").setValue("") ; Ext.getCmp("age").setValue("") ;} } }
]
}
]
},
{ title: "删除信息", id: "del" },
{ title: "查询信息", id: "query" }
]
});
/////////整体界面
new Ext.Viewport
({
enableTabScroll: true,
layout: "border",
items:
[ {
title: "学生信息管理系统",
region: "north",
height: 100,
html: "<center><h2>学生信息管理系统</h2></center>"
},
fpanel,
contentPanel
]
});
};
////////////////数据交互函数
function validatorData(){
var ID=Ext.getCmp("id").getValue();
var Name=Ext.getCmp("name").getValue();
var Age=Ext.getCmp("age").getValue();
var Sex="男";//Ext.getcmp("userSex").getGroupValue();
if(Ext.util.Format.trim(ID)==""||Ext.util.Format.trim(Name)==""||Ext.util.Format.trim(Age)==""){
Ext.Msg.alert("警告","请将信息填写完整!");
return;
}
Ext.Msg.alert("消息",ID+Name+Age+Sex);
Ext.Ajax.request({
//请求的地址
url:'Default.aspx?parm=insert',
method: 'POST',
//发送的参数
params:{ParamValue:"1",ParamID:ID,ParamName:Name,ParamSex:Sex,ParamAge:Age},
//params:{ParamValue:"1",ParamUserName:UserName,ParamPassword:Password}
success:function(response,option){
var obj=Ext.util.JSON.decode(response.responseText);//返回的信息
Ext.Msg.alert("好消息","储存成功!");
},
failure:function(){
Ext.Msg.alert("坏消息","存取异常!");
}
})
}
/////////////////////
function Login()
{
//界面设计函数
LoginLayout();
//validatorData();
} Ext.onReady(Login);
</script>
</div>
</form>
</body>
</html>这是 Default.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="asp_extjs._Default" %>这是Default.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;using Service;//添加命名空间
using System.Data.SqlClient;
using System.Web.Script.Serialization;//Json序列化
using System.Text;namespace asp_extjs
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
String ParamValue = Request.QueryString["parm"].ToString();
if (ParamValue == "insert")
{
String ID = Request.QueryString["ParamID"].ToString();
String Name = Request.QueryString["ParamName"].ToString();
String Age = Request.QueryString["ParamAge"].ToString();
String Sex = Request.QueryString["ParamSex"].ToString();
Console.Write(ID + Name + Age + Sex);
Console.Out.WriteLine("开始插入!"); ///////////////////////////
String sql = "insert into student values('" + ID + "','" + Name + "','" + Age + "'," + Sex + ")";
try
{
// int count = cmd.ExecuteNonQuery();
int count = Service.DBHelper.ExecuteCommand(sql);
if (count != 0)
{
Response.Write("{success:true}");
}
else
{
// Response.Write("{success:true}");
Response.Write("{success:false}");
}
}
catch (Exception)
{
throw;
}
}
}
}
}