日期:2014-05-18  浏览次数:20411 次

如何用javascript调用后台函数
我想在页面加载完毕后在接着调用这个页的一个后台函数,不知道在onload事件怎么写
请指教

------解决方案--------------------
<head runat= "server ">
<title> 无标题页 </title>
<script type= "text/javascript ">
function pageload()
{
document.getElementById( "pageDIV ").innerHTML= '23423 ';
}
</script>
</head>
<body>
<form id= "form1 " runat= "server ">
<div id= "pageDIV ">

</div>
<div id= "resultList "> <script type= "text/javascript "> pageload() </script> </div>
</form>
</body>
</html>

<div id= "resultList "> 紧贴着form放置
------解决方案--------------------
<script>
//温泉
//2007-4-28
//XmlHttpRequest
//服务器端异步调用
//前台Aspx页面的javascript脚本
var xmlHttp ;
var result = " ";

function SendData(url)
{
if (window.ActiveXObject)
{
xmlHttp = new ActiveXObject( "Microsoft.XMLHTTP ");
}
else if (window.XMLHttpRequest)
{
xmlHttp = new XMLHttpRequest();
}
xmlHttp.open( "GET ", url, true);
xmlHttp.onreadystatechange=callBack;
xmlHttp.send( " "); 
}

function callBack()
{
if(xmlHttp.readyState==4&&xmlHttp.status==200)
{
result = xmlHttp.responseText;
alert( "后台返回: "+result);
}
}

SendData( "?action=123 ");
</script>

/******************************************/

//后台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 Error : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if(!string.IsNullOrEmpty(Request.QueryString[ "action "]))
{
Response.Write( "Hello DotNet ");
Response.End();
Return;
}
}
}


我一般都是这样做的