当前位置: 代码迷 >> ASP.NET >> Ajax.NET Professional 怎么请页面
  详细解决方案

Ajax.NET Professional 怎么请页面

热度:8575   发布时间:2013-02-25 00:00:00.0
Ajax.NET Professional 如何请求一个页面


使用Ajax.NET Professional框架,如何在页面test1的一个div里显示页面test2?

------解决方案--------------------------------------------------------
iframe
------解决方案--------------------------------------------------------
UP
------解决方案--------------------------------------------------------
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_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>
<script type="text/javascript">
var xmlHttp;
function createXMLHttpRequest()
{
if(window.ActiveXObject)
{
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
else if(window.XMLHttpRequest)
{
xmlHttp = new XMLHttpRequest();
}
}
function GetTest2()
{
createXMLHttpRequest();
var url= "test2.aspx";
xmlHttp.open("GET",url,true);
xmlHttp.onreadystatechange=showResult;
xmlHttp.send(null);
}
function showResult()
{
if(xmlHttp.readyState==4)
{
if(xmlHttp.status==200)
{
document.getElementById("test2Div).innerHTML=xmlHttp.responseText;
}
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div style="text-align: center" id ="test2Div">
</div>
</form>
</body>
</html>



//没有经过测试,自已试一下吧
------解决方案--------------------------------------------------------
//嗯。。。重写一个吧。。。

HTML code
//ajaxtest.aspx<%@ Page Language="C#" AutoEventWireup="true" CodeFile="AjaxTest.aspx.cs" Inherits="Share_AjaxTest" %><!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>           <script   type="text/javascript">                 var   xmlHttp;                 function   createXMLHttpRequest()                 {                         if(window.ActiveXObject)                         {                                 xmlHttp   =   new   ActiveXObject("Microsoft.XMLHTTP");                         }                         else   if(window.XMLHttpRequest)                         {                                 xmlHttp   =   new   XMLHttpRequest();                         }                 }                 function   GetTest2()                 {                         createXMLHttpRequest();                         var id  = document.getElementById("Text1").value;                                                var   url=   "ajaxtest2.aspx?id=" + id;                         xmlHttp.open("GET",url,true);                         xmlHttp.onreadystatechange=showResult;                         xmlHttp.send(null);                 }                 function   showResult()                 {                                                if(xmlHttp.readyState==4)                         {                                 if(xmlHttp.status==200)                                 {                                     var Req = xmlHttp.responseText;                                                                        //取<form>和</form>中间的内容                                    var re=new RegExp(/(<form)([\s\S]+?)(>)([\s\S]+?)(<\/form>)/);                                    if(re.test(Req))                                        Req=RegExp.$4;                                    document.getElementById("test2Div").innerHTML=Req;                                 }                         }                 }         </script> </head><body>    <form id="form1" runat="server">    <div>        传递参数 :<input id="Text1" type="text" value="0" />        <input id="Button1" type="button" value="button" onclick="GetTest2()" />        <div id="test2Div" style="width: 280px; height: 199px; position:absolute; left: 194px; top: 82px;border:1px solid #afafaf;">        </div>        </div>    </form></body></html>
  相关解决方案