2012-04-07 13 views
1

現在、私はJavaScriptを使って作成した配列をmy aspx.cs.xのwebmethodに渡そうとしています。JavaScriptを使用してWebメソッドに配列を渡す

は、相続人は私が持っているもの:それも私のWebメソッドに到達する前に

JAVASCRIPT

function callServer(requestMethod, clientRequest) { 


    var pageMethod = "Default.aspx/" + requestMethod; 
    $.ajax({ 
     url: pageMethod, // Current Page, Method 
     data: JSON.stringify({ request: clientRequest }), // parameter map as JSON 
     type: "POST", // data has to be POSTed 
     contentType: "application/json", // posting JSON content  
     dataType: "JSON", // type of data is JSON (must be upper case!) 
     timeout: 60000, // AJAX timeout 
     success: function (result) { 
      ajaxCallback(result.d); 
     }, 
     error: function (xhr, status) { 
      alert(status + " - " + xhr.responseText); 
     } 
    }); 
} 



function myButtonCalls() 
{ 
var values=[]; 
values[0] = "Hello"; 
values[1] = "goodbye"; 

callServer("myMethod", values); 
} 

ASPX.CS

[WebMethod] 
     public static string myMethod(string[] request) 
     { 
return "This is test"; 
    } 

それは失敗します。私はこのコードがregualrの文字列で動作することを知っていますが、JSONを使用するajaxコードは配列を扱いたいと思っていません。

私は何を変更する必要がありますか?

ありがとう

+0

Developer ToolsでajaxリクエストをChromeまたはFirefoxでデバッグしてみてください。どちらの方からも、サーバーからどのような応答が得られているかを教えてください。 –

+1

私はこれのサーバー側に慣れていないと認めますが、このポストヘルプはありますか? http://stackoverflow.com/questions/3191317/passing-array-to-webmethod-using-ajax – dfreeman

+0

@dfreemanそれはありがとう、それは私が必要なものを正確に持っていたそのポストの別の質問に私を導く:) – Johnston

答えて

0

aspx.csでは、タイプリストではなく配列を受け入れる必要がありました。コメントありがとう!

関連する問題