当前位置: 代码迷 >> ASP.NET >> ajax和asp.net怎么结合呀? 已经有前台.html 后台怎么传参数给它
  详细解决方案

ajax和asp.net怎么结合呀? 已经有前台.html 后台怎么传参数给它

热度:324   发布时间:2013-02-25 00:00:00.0
ajax和asp.net如何结合呀? 已经有前台 后台如何传参数给它?
前台ajax:
<script   language= "JavaScript ">  
function   GetResult()  
{  
var   oBao   =   new   ActiveXObject( "Microsoft.XMLHTTP ");  
oBao.open( "POST ", "admin.aspx.cs ",false);  
oBao.send();  
var   strResult   =   unescape(oBao.responseText);  
//将字符串分开.  
var   arrResult   =   strResult.split( "### ");  
RemoveRow();   //删除以前的数据.  
//将取得的字符串分开,并写入表格中.  
for(var   i=0;i <arrResult.length;i++)  
{  
arrTmp   =   arrResult[i].split( "@@@ ");  
num1   =   arrTmp[0];   //字段num1的值  
//num2   =   arrTmp[1];   //字段num2的值  
row1   =   tb.insertRow();  
cell1   =   row1.insertCell();  
cell1.innerText   =   num1;  
//cell2   =   row1.insertCell();  
//cell2.innerText   =   num2;  
}  
}  

function   RemoveRow()  
{  
//保留第一行表头,其余数据均删除.  
var   iRows   =   tb.rows.length;  
for(var   i=0;i <iRows-1;i++)  
{  
tb.deleteRow(1);  
}  
}  

function   MyShow()  
{  
//1秒自动刷新一次,1秒取得一次数据.  
timer   =   window.setInterval( "GetResult() ",1000);  
}  
</script>  

<body   onload= "MyShow() ">  
<p>  
</p>  
<marquee   truespeed   behavior= "scroll "     HSPACE= "0 "     VSPACE= "0 "     scrollamount=     '6 '   scrolldelay=     '85 '   direction= 'up '>
<table   width= "47% "   height= "23 "   border= "0 "   cellpadding= "1 "   cellspacing= "0 "   id= "tb ">  
<tr>  


</tr>  
</table>  
</marquee>

后台:admin.aspx.cs

using   System;


using   System.Data;
using   System.Data.OleDb;

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;
using   System.Text;//StringBuilder   类命名空间
using   System.IO;//读取写入命名空间


        //访问数据库,并返回数据
private   void   main()
{
string   dbPath=System.Configuration.ConfigurationSettings.AppSettings[ "dbpath "];
OleDbConnection   oleConnection   =   new   OleDbConnection( "Provider=Microsoft.Jet.OLEDB.4.0;   Data   source= "   +   Server.MapPath(dbPath));
//string   Sql   =   "SELECT   *   FROM   book ";


OleDbCommand   cmd=new   OleDbCommand( "SELECT   *   FROM   nums   ORDER   BY   id   DESC ",oleConnection);
cmd.CommandType   =   CommandType.Text;
try
{
cmd.Connection.Open();
OleDbDataReader   dr=   cmd.ExecuteReader();
  相关解决方案