Asp.net 按钮onclient单击callajax
在我的asp.net应用程序中,有一个按钮定义为: Asp.net C代码Asp.net 按钮onclient单击callajax,asp.net,ajax,web-services,Asp.net,Ajax,Web Services,在我的asp.net应用程序中,有一个按钮定义为: Asp.net C代码 一切正常,但OnSuccess函数未被激发。我在jsonlint.com上检查了我的JSON数据格式,并对其进行了验证。有人能帮我找到问题吗 尝试此操作…在传递参数时删除单引号 $.ajax({ type: "POST", url: "Options.aspx/GetDataForChart", contentType: "
一切正常,但OnSuccess函数未被激发。我在jsonlint.com上检查了我的JSON数据格式,并对其进行了验证。有人能帮我找到问题吗 尝试此操作…在传递参数时删除单引号
$.ajax({
type: "POST",
url: "Options.aspx/GetDataForChart",
contentType: "application/json; charset=utf-8",
dataType: "json",
data:{ sensorId: sensorId, startDate: startDate, endDate: endDate},
success: function (data){chart = new Highcharts.StockChart(levelChartData);
var historyData1 = [],
historyData2 = [],
series1 = chart.series[0], //level data
series2 = chart.series[1]; //freshness timer
$.each(data.d, function () {
x = (new Date(Date.parse(this.SensorDataInfo.ServerTime))).getTime(), // current time
y = this.levelData.y,
z = this.levelData.z;
historyData1.push([x, y]);
historyData2.push([x, z]);
})
series1.setData(historyData1);
series2.setData(historyData2);
},
error: function (response) {
alert(response.status);
}
});
如果不起作用一定要告诉我
function GenerateHistoryChart()
{
if ($("#HistoryDisplayType").val() === "Graph")
{
var sensorId = $("#SensorIdListBox option:selected").val();
var startDate = $("#StartHistoryDate").val();
var endDate = $("#EndHistoryDate").val();
$.ajax({
type: "POST",
url: "Options.aspx/GetDataForChart",
contentType: "application/json; charset=utf-8",
dataType: "json",
data: '{ sensorId:"'+ sensorId +'", startDate:" '+startDate +'", endDate: "'+ endDate +'"}',
success: OnSuccess,
error: function (response) {
alert(response.status);
}
});
// return false;
}
else
return true;
}
function OnSuccess(data)
{
chart = new Highcharts.StockChart(levelChartData);
var historyData1 = [],
historyData2 = [],
series1 = chart.series[0], //level data
series2 = chart.series[1]; //freshness timer
$.each(data.d, function () {
x = (new Date(Date.parse(this.SensorDataInfo.ServerTime))).getTime(), // current time
y = this.levelData.y,
z = this.levelData.z;
historyData1.push([x, y]);
historyData2.push([x, z]);
})
series1.setData(historyData1);
series2.setData(historyData2);
}
[System.Web.Services.WebMethod]
public static List<object> GetDataForChart(string sensorId, string startDate, string endDate)
{
List<SD> result = SensorMapper.Instance.GetSensorHistory(Int64.Parse(sensorId), DateTime.Parse(startDate), DateTime.Parse(endDate));
List<object> result2 = new List<object>();
result2.AddRange(result.Select(r => new object[] { r.SensorDataInfo.ServerTime, r.temperatureData.temp }));
return result2;
}
$.ajax({
type: "POST",
url: "Options.aspx/GetDataForChart",
contentType: "application/json; charset=utf-8",
dataType: "json",
data:{ sensorId: sensorId, startDate: startDate, endDate: endDate},
success: function (data){chart = new Highcharts.StockChart(levelChartData);
var historyData1 = [],
historyData2 = [],
series1 = chart.series[0], //level data
series2 = chart.series[1]; //freshness timer
$.each(data.d, function () {
x = (new Date(Date.parse(this.SensorDataInfo.ServerTime))).getTime(), // current time
y = this.levelData.y,
z = this.levelData.z;
historyData1.push([x, y]);
historyData2.push([x, z]);
})
series1.setData(historyData1);
series2.setData(historyData2);
},
error: function (response) {
alert(response.status);
}
});