日期:2014-05-17 浏览次数:20496 次
<script src="http://code.jquery.com/jquery-1.10.1.js"></script>
<script>
$(document).ready(function () {
var myCars = new Array();
myCars[0] = "Saab";
myCars[1] = "Volvo";
myCars[2] = "BMW";
$.ajax({
type: "POST",
url: "<%=Request.Url.AbsolutePath%>/Concat",
data: JSON.stringify({ arr: myCars }),
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (response) {
alert(response.d);
},
failure: function () {
alert("fail");
}
});
});
</script>
[System.Web.Script.Services.ScriptService]
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
[WebMethod]
public static string Concat(List<string> arr)
{
string result = "";
for (int i = 0; i < arr.Count; i++)
{
result += arr[i];
}
return result;
}
}