<script language="javascript" type="text/javascript">
var request = false;
try {
request = new XMLHttpRequest();
} catch (trymicrosoft) {
try {
request = new ActiveXObject("Msxml2.XMLHTTP");
} catch (othermicrosoft) {
try {
request = new ActiveXObject("Microsoft.XMLHTTP");
} catch (failed) {
request = false;
}
}
}
if (!request)
alert("Error initializing XMLHttpRequest!");
function getCustomerInfo() {
var phone = document.getElementById("phone").value;
var url = "/cgi-local/lookupCustomer.aspx?phone=" + escape(phone);//传递加密后的phone
request.open("GET", url, true);
request.onreadystatechange = updatePage;
request.send(null);
}
function updatePage() {
if (request.readyState == 4) {
if (request.status == 200) {
var response = request.responseText.split("|");
document.getElementById("order").value = response[0];
document.getElementById("address").innerHTML =
response[1].replace(/\n/g, "");
} else
alert("status is " + request.status);
}
}
</script>提出问题,在/cgi-local/lookupCustomer.aspx对传递过去的phone经行一系列操作后,如何将需要的值传回本页面?
var response = request.responseText.split("|");
document.getElementById("order").value = response[0];
document.getElementById("address").innerHTML =
response[1].replace(/\n/g, "");
这其中的request.responseText如何得到值呢?
查看了很多资料,但还是很不理解,哪位高手给讲解一下啊?
var request = false;
try {
request = new XMLHttpRequest();
} catch (trymicrosoft) {
try {
request = new ActiveXObject("Msxml2.XMLHTTP");
} catch (othermicrosoft) {
try {
request = new ActiveXObject("Microsoft.XMLHTTP");
} catch (failed) {
request = false;
}
}
}
if (!request)
alert("Error initializing XMLHttpRequest!");
function getCustomerInfo() {
var phone = document.getElementById("phone").value;
var url = "/cgi-local/lookupCustomer.aspx?phone=" + escape(phone);//传递加密后的phone
request.open("GET", url, true);
request.onreadystatechange = updatePage;
request.send(null);
}
function updatePage() {
if (request.readyState == 4) {
if (request.status == 200) {
var response = request.responseText.split("|");
document.getElementById("order").value = response[0];
document.getElementById("address").innerHTML =
response[1].replace(/\n/g, "");
} else
alert("status is " + request.status);
}
}
</script>提出问题,在/cgi-local/lookupCustomer.aspx对传递过去的phone经行一系列操作后,如何将需要的值传回本页面?
var response = request.responseText.split("|");
document.getElementById("order").value = response[0];
document.getElementById("address").innerHTML =
response[1].replace(/\n/g, "");
这其中的request.responseText如何得到值呢?
查看了很多资料,但还是很不理解,哪位高手给讲解一下啊?
解决方案 »
- 关于combobox的问题,请高手指教!
- 关于构造函数
- 高分___问大伙一个简单问题
- | 问题
- 在tcpclient.GetStream()之后进行构造其他对象出现组塞为什么?
- 菜鸟问题???
- 怎么去掉这类版权保护
- 用c#能写出RealPlayer播放器那让的界面么
- GetElementsByTagName取不到对应值,菜鸟求助
- 那位大侠会做windows 2000 的个性化菜单,小生这里谢过了1
- Dictionary.ContainsKey和List.BinarySearch哪个效率高
- VS2005 C# 项目中创建了个文件夹,保存了一些图片,在程序运行过程中调用! 但不输出到bin\debug目录下
http://www.cnblogs.com/ustbwuyi/archive/2007/03/19/679586.html
var result=request.responseText;
var results=result.split(",");for(var i=0;i<results.length;i++)
{
var str=results[i];
var ID=str.substring(0,str.indexOf("|"));
var Name=str.substring(str.indexOf("|")+1,str.length);
document.....
}
我现在要做的一个程序是这样的:
数据库是这样设计的:
table1存了用户编号,员工姓名.其中用户编号和员工姓名是一对多的,也就是说一个用户编号下可以存在多个员工.我想实现的是,在TextBox中输入用户编号后,当焦点离开TextBox时,DropdownList中立即获取该用户编号对应的所有员工姓名.
if (request.status == 200) {
var response = request.responseText.split(" ¦");
var select = document.getElementById("你的dorpdownlist的id");
select.length = 0;
for(var i=0;i<response.length;i++)
{
select.options.add(new Option(response[i],""))
}
}
我还在尝试
最主要的问题不是本页,而是
var url = "/cgi-local/lookupCustomer.aspx?phone=" + escape(phone);//传递加密后的phone
request.open("GET", url, true);
在lookupCustomer.aspx内部将数据准备好之后,是不是通过Response.Write("我需要的数值,也就是员工姓名");
这样就把值传递回来了?
我这样写会报错
<asp:TextBox ID="UserName" runat="server" OnTextChanged="getCustomerInfo()"></asp:TextBox>
<script language="javascript" type="text/javascript">
var request = false;
//创建新的 XMLHttpRequest 对象
try {
request = new XMLHttpRequest();
} catch (trymicrosoft) {
try {
request = new ActiveXObject("Msxml2.XMLHTTP");
} catch (othermicrosoft) {
try {
request = new ActiveXObject("Microsoft.XMLHTTP");
} catch (failed) {
request = false;
}
}
}
if (!request)
{
alert("Error initializing XMLHttpRequest!");
}
//发送请求
function getCustomerInfo()
{
var UserName = document.getElementById("UserName").value;
var url = "getCustomerInfo.aspx?UserName=" + UserName;
request.open("GET", url, true);
request.onreadystatechange = updatePage;
request.send(null);
}
//获得数据后,在本页进行处理
function updatePage()
{
if (request.readyState == 4)
{
if (request.status == 200)
{
//清空原下拉框
document.getElementById("Customer").options.length=0;
//str为返回的一个字符串,形式为"员工1,员工2,..."
var str=request.responseText;
//将该字符串分割为数组形式
var strs=str.split(",");
if(strs[0] == "error")
{
document.getElementById("Customer").options.add(new Option("用户名不存在,请检查",0));
document.getElementById("Customer").Enable = false;
}
for(var i=0;i<strs.length-1;i++)
{
//获得员工姓名
var Customer = strs[i];
//绑定到下拉框
document.getElementById("Customer").options.add(new Option(Customer));
}
}
else
alert("status is " + request.status);
}
}
</script>getCustomerInfo.aspx:
protected void Page_Load(object sender, EventArgs e)
{
Response.Write("error");
}
这是我的代码,报错,缺少对象.为什么?
不能用asp.net的控件吗?
{
document.getElementById("Customer").options.add(new Option("用户名不存在,请检查",0));
document.getElementById("Customer").Enable = false;
}
else
{
//将该字符串分割为数组形式
var strs=str.split(",");
for(var i=0;i<strs.length-1;i++)
{
//获得员工姓名
var Customer = strs[i];
//绑定到下拉框
document.getElementById("Customer").options.add(new Option(Customer));
}
} 我在getCustomerInfo.aspx中只写了Response.Write("error"); ,请帮我看看上面的程序有什么问题,为什么不执行呢?
for(var i=0;i <strs.length-1;i++) ==》for(var i=0;i <strs.length;i++) document.getElementById("Customer").options.add(new Option(Customer)); new Option()应该带两个参数吧
这样改动后,如果在getCustomerInfo.aspx中只写了Response.Write("error"); ,dropdownList中会添加一条error<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">...的很长的信息如果在getCustomerInfo.aspx中只写了Response.Write("员工1,员工2,员工3");,dropdownList中在"员工3"的那一行会添加一条error<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">...的很长的信息不知道为什么啊
<head runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
</form>
</body>
</html>你把这个页面的页面html全部删掉,只留第一句就可以了<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="Plug_Default" %>
因为后面的
<!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">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
</form>
</body>
</html>
这部分也输出返回了
这样改动后,如果在getCustomerInfo.aspx中只写了Response.Write("error"); ,dropdownList中会添加一条error <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> ...的很长的信息如果在getCustomerInfo.aspx中只写了Response.Write("员工1,员工2,员工3");,dropdownList中在 "员工3"的那一行会添加一条员工3<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> ...的很长的信息不知道为什么啊?