2011-07-12 28 views
-1

喜如何通過陣列,同時在數組,如何傳遞數組在jQuery中從C#代碼C#應用程序?

double[] A={0.8446, 0.8445, 0.8444, 0.8451}; 

從C#代碼將jQuery我試圖這​​樣,

<script type="text/javascript"> 

     function Drawgraph(){ 
      var chart; 
      alert ("<%= A %>"); 
       series: [{ 
         type: 'area', 
         name: 'Power to USD', 
         //pointInterval: 24 * 3600 * 1000, 
         //pointStart: Date.UTC(2011, 0, 01), 
         point:Arr, 
         data: Arr 

的希望幫忙

+0

可能重複[如何傳遞參數在jQuery函數C#Web應用程序?(http://stackoverflow.com/questions/6649884/如何傳遞參數在jQuery的 - 功能 - c - web應用程序) – Magnus

+0

我沒有回答這個昨天... – Magnus

回答

0

只需使用JavaScriptSerializer和寫列入一個Javascript變量:

var data = <%new JavaScriptSerializer().Serialize(A)%> 

Ou輸入:

var data = [0.8446,0.8445,0.8444,0.8451]; 
0

我建議使用JSON爲此。查看website瞭解更多信息。

您可以使用JavaScriptSerializer來實現您的目標。

[WebMethod, ScriptMethod(ResponseFormat = ResponseFormat.Json, UseHttpGet = true)] 
public object GetDoubles() 
{ 
    return new { 0.8446, 0.8445, 0.8444, 0.8451 }; 
} 

爲了得到這個客戶端使用的JQuery AJAX

$.ajax({ 
    url: 'SomeService.asmx/GetDoubles', 
    type: 'GET', 
    contentType: 'application/json', 
    success: function(data){ 
     // access using data (or data.d) 
     $(data.d).each(function(){ 
      alert(this); 
     }); 
    } 
}); 
相關問題