1
我做了一个Web服务,其中我有一个函数来计算我的SQL数据库中的一些数据。我WebService.asmx的下面的代码:Javascript的ASMX Web服务
[System.Web.Script.Services.ScriptService]
public class WebService1 : System.Web.Services.WebService
{
[WebMethod]
public int SalesNumberMonth(int i)
{
int total = 0;
SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["Sql"].ConnectionString);
try
{
string request = "SELECT * FROM sales_Ventes V INNER JOIN sys_AnneesFiscales A ON V.AnneeFiscale = A.Code INNER JOIN sys_Mois M ON V.Mois = M.Code WHERE M.Code='" + i + "'" + " AND Active = 'true'";
connection.Open();
SqlCommand Req = new SqlCommand(request, connection);
SqlDataReader Reader = Req.ExecuteReader();
while (Reader.Read())
{
total++;
}
Reader.Close();
}
catch
{
}
connection.Close();
return total;
}
}
,在这里我的script.js:
var sin = [], cos = [];
for (var i = 1; i < 13; i += 1) {
GestionPro.WebService1.SalesNumberMonth(i, function (e) { sin.push([i, e]); } ,function (response) { alert(response); } );
cos.push([i, 2]);
}
var plot = $.plot($("#mws-test-chart"),
[{ data: sin, label: "Sin(x)²", color: "#eeeeee" }, { data: cos, label: "Cos(x)", color: "#c5d52b"}], {
series: {
lines: { show: true },
points: { show: true }
},
grid: { hoverable: true, clickable: true }
});
我probleme是在这条线:
GestionPro.WebService1.SalesNumberMonth(i, function (e) { sin.push([i, e]); } ,function (response) { alert(response); } );
当我换了两个函数,警报显示的很好,但是按照这个顺序,我不能在sin []中添加我的函数的值。我错过了什么,但不知道是什么...
你确定你想在一个打电话给你的web服务13次循环?如果你有两个客户同时打开这个页面怎么办?这使得它可以同时呼叫26个。如果你有10个客户端 - 同时发生130个AJAX调用!!!你认为你的服务器在崩溃之前会走多远?此外,为什么你使用'SELECT *'然后在.NET代码中使用累加器变量来计数?你没有听说过COUNT SQL集合函数吗? –