读书人

asp.net中使用iframe实现无刷新功能解

发布时间: 2012-01-05 22:36:54 作者: rapoo

asp.net中使用iframe实现无刷新功能
项目需要做一个录入界面,这个界面有很多TextBox,需向TextBox录入代码,回车后自动刷新,在TextBox显示该代码对应的中文。因为对Javascript不是特别熟悉,麻烦给个例子,谢谢!

[解决办法]
直接使用AJAX,你的需求很简单,网上很多
[解决办法]
要实现无刷新功能还是用AJAX吧,简单实用,这里有很多视频教程
http://bbs.langsin.com/forumdisplay.php?fid=21
[解决办法]
先写一个脚本
function click()
{
var s=document.getElementById( 'textbox1 ');
...
var url= 'XX.aspx?参数 ';
Request(url,其它参数);
}
function CreateXMLHttpRequest() {
var request = false;
if (window.XMLHttpRequest) {
request = new XMLHttpRequest();
if (request.overrideMimeType) {
request.overrideMimeType( 'text/xml ');
}
} else if (window.ActiveXObject) {
try {
request = new ActiveXObject( "Msxml2.XMLHTTP ");
} catch (e) {
try {
request = new ActiveXObject( "Microsoft.XMLHTTP ");
} catch (e) {return false;}
}
}
if (!request) {
alert( 'Create XMLHTTP Object false. ');
return false;
}
return request;
}
function Request(url, 其它参数) {
var http_request = CreateXMLHttpRequest();
var content=new Array();
ShowOrHidden(tableId);
http_request.open( 'GET ', url, true);
http_request.onreadystatechange=function()
{
if(http_request.readyState==4)
{
if(http_request.status==200)
{

document.getElementById( "div_content ").innerHTML =content;;



}
}
}
http_request.send(null);

}

}
}
[解决办法]
用AJAX来实现。。。
[解决办法]
1. xmlhttp + iframe
2. ajxa


[解决办法]
参考页:
http://www.hunanbook.com/Register.html
[解决办法]
如果只是让一边刷新的话js就能解决了
[解决办法]
用iframe和ajax都能实现

不过按你说的流程 用iframe不如ajax实现简单 因为除非你将iframe嵌套的页中已经含有代码转换成中文的程序 否则在后台转换还是要刷新 或者也得后台程序来做 这样还不如直接用ajax
[解决办法]
大家说的很全面了
[解决办法]
这个问题看起来很简单,其实代码却要写好多的,用AJAX实现.我等下发个例子给你
[解决办法]
路过,学习
[解决办法]
我来拉,例子奉上.搞老半天才搞完,郁闷.

content.htm:

<!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>
<title> 无标题页 </title>
</head>
<script>
var xmlHttp;
var message;
var target;
function createXMLHttpRequest()
{
if(window.ActiveXObject)
{
xmlHttp=new ActiveXObject( "Microsoft.XMLHTTP ");
}
else if(window.XMLHttpRequest)
{
xmlHttp=new XMLHttpRequest();
}
}

function doRequest(txt)
{
target=document.getElementById(txt).id;
createXMLHttpRequest();
var content=document.getElementById(txt).value;
xmlHttp.onreadystatechange=getRequest;
var url= "process.aspx?task= "+content;
xmlHttp.open( "GET ",url,true);
xmlHttp.send(null);
}
function getRequest()
{
if(xmlHttp.readyState==4)
{
if(xmlHttp.status==200)
{
Ajax();
}
}
}

function Ajax()
{
message=xmlHttp.responseXml.getElementsByTagName( "root ")[0].firstChild.data;
document.getElementById(target).value=message;
}

</script>
<body>
<input type= "text " name= "txt1 " id= "txt1 " onchange= "doRequest(this.id) " />
<input type= "text " name= "txt2 " id= "txt2 " onchange= "doRequest(this.id) " />
</body>
</html>


process.aspx:
<%@ Page Language= "C# " AutoEventWireup= "true " CodeFile= "process.aspx.cs " Inherits= "process " %>

注意:process.aspx中只有这一段代码,把其他的都删了(因为要返回XML数据)

process.aspx.cs:

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class process : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string task = Request.QueryString[ "task "].ToString();
string content = null;
if (task.Equals( "aaa "))
{
content = "肖 ";
}
if(task.Equals( "bbb "))
{
content = "俊 ";
}

Response.Clear();
Response.ContentType = "text/xml ";
Response.Write( " <root> ");
Response.Write(content);
Response.Write( " </root> ");
}
}


[解决办法]
说明下这个例子把,这个例子的功能就是有content.htm里面有两个文本框,当你在文本框中输入 "aaa "时,就自动转换成 "肖 ",当你输入 "bbb "时,就自动转换成 "俊 ".这个是Ajax异步处理的原理.
但我感觉有点傻呼呼的,为什么不直接在onchange中直接转换呢?还要跳到另一个页面去处理,我自己也糊涂了....
[解决办法]
up
[解决办法]
本页的代码都是这么写的
function getRequest()
{
if(xmlHttp.readyState==4)
{
if(xmlHttp.status==200)
{
Ajax();
}
}
}



难道不用处理超时吗?初学AJAX 请教
[解决办法]
up
[解决办法]
这个问题提的好 ,我还真没去注意超时的问题,因为平时就这么写了,都没发现请求超时的现象.
等去问下公司的牛人
[解决办法]
在TextBox显示该代码对应的中文

=======

虾米意思哦 ......
[解决办法]
傻子来了,拿大家的代码都来试试.学了点点东西,哈哈哈哈!~~~~~~~~~

读书人网 >asp.net

热点推荐