假设在服务器端计算得到了一个数组s需要传递到JavaScript中的名为my_array的数组继续进行处理:  
protected  int[]  s;//protected  or  public  is  required  
为了测试给s赋几个值:  
s  =  new  int[100];  
for  (int  i=0;  i<s.Length;  i++)  
{  
           s[i]  =  i;  
}  
-------------------------------------------------------------------  
方法一(ASP风格,不推荐):  
In  the  aspx  page:  
<script  language="javascript">  
           //将cs中的数组传js中的数组  
           var  my_array  =  new  Array(100);  
           <%  
                       string  iniArr  =  null;  
                       for  (int  i=0;  i<100;  i++)  
                       {  
                                   iniArr  +=  "my_array["  +  i  +  "]="  +  s[i]  +  ";";  
                       }  
           %>  
           <%=iniArr%>  
           //下面为测试用代码  
           for  (i=0;  i<100;  i++)  
           {  
                       document.all("num").innerText  +=  my_array[i];    
           }  
</script>  
 
-------------------------------------------------------------------  
方法二(使用webservice,感谢bitsbird提供了代码):  
<!DOCTYPE  HTML  PUBLIC  "-//W3C//DTD  HTML  4.0  Transitional//EN"  >  
<HTML>  
 <HEAD>  
   <title>RealTime</title>  
   <meta  name="GENERATOR"  Content="Microsoft  Visual  Studio  .NET  7.1">  
   <meta  name="CODE_LANGUAGE"  Content="C#">  
   <meta  name="vs_defaultClientScript"  content="JavaScript">  
   <meta  name="vs_targetSchema"  content="http://schemas.microsoft.com/intellisense/ie5">  
   <script  language="javascript">  
 var  intCallID=0;  
 function  Init()  
 {  
 GetNewFeatured();  
 setInterval("GetNewFeatured()",10000);  
 }  
 function  GetNewFeatured()  
 {  
     Service.useService("http://localhost/WebService/LoadData/FeaturedService.asmx?WSDL","FeaturedService");  
     intCallID=Service.FeaturedService.callService(RealTime_Result,"GetScores");  
 }  
 function  RealTime_Result(result)  
 {  
   if(result.error)  
   {  
     divFeatured.innerHTML=result.errorDetail.string;  
   }  
   else  
   {  
   divFeatured.innerHTML=result.value;  
   }  
 }  
 </script>  
 </HEAD>  
 <body  onload="Init()">  
   <div  >http://community.csdn.net/Expert/FAQ/FAQ_Index.asp?id=209336

相关文章:

  • 2022-02-15
  • 2021-12-31
  • 2021-12-26
  • 2021-06-02
  • 2021-12-13
  • 2022-12-23
  • 2021-11-17
  • 2021-10-11
猜你喜欢
  • 2022-01-15
  • 2022-12-23
  • 2022-12-23
  • 2022-02-20
  • 2021-05-19
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案