여기에서 나는 버튼 클릭에 자바 스크립트 함수를 호출하고 있는데, 자바 스크립트 함수 내에서 서버 측 메서드를 호출해야한다.자바 스크립트 함수에서 서버 측 메소드 호출?
자바 스크립트 함수
function exportCharts(exportFormat) {
initiateExport = true;
for (var chartRef in FusionCharts.items) {
if (FusionCharts.items[chartRef].exportChart) {
document.getElementById("linkToExportedFile").innerHTML = "Exporting...";
FusionCharts.items[chartRef].exportChart({ "exportFormat": exportFormat });
}
else {
document.getElementById("linkToExportedFile").innerHTML = "Please wait till the chart completes rendering...";
}
}
}
서버 측 방법
protected void imgBTNExportPPT_Click(object sender, ImageClickEventArgs e)
{
try
{
PredictExportToPPT objOExporttoPPT = new PredictExportToPPT();
PredictionModel();
string reportNames = ObjCommon.GetBIReportNames("Prediction", "Report");
reportNames += ObjCommon.GetBIReportNames("Prediction", "Table");
objOExporttoPPT.ExportToPPTPredict(ObjPredictInputParameter, reportNames, ObjSharedEntities.PredictTableData);
string itemname = "PPTOutput.pptx";
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.ContentType = "pptx";
HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename=" + itemname + "");
HttpContext.Current.Response.BinaryWrite(System.IO.File.ReadAllBytes(HttpContext.Current.Server.MapPath(DataTemplate.PPTOutputTemplateFilePath)));
HttpContext.Current.Response.Flush();
HttpContext.Current.Response.End();
}
catch (Exception exceptionMessage)
{
throw (exceptionMessage);
}
finally
{
GC.Collect();
}
}
는 난이
$(document).ready(function() {
$("#imgBTNExportPPT").click(function (e) {
e.imgBTNExportPPT_Click();
$.ajax({
type: "POST",
url: "PEventPerformance.aspx/updateContent",
data: "{}",
success: function (result) {
}
});
});
});
어떤 제안 같은 시도 ??
imgBTNExportPPT_Click 버튼을 클릭해도 #imgBTNExportPPT JS가 울리지 않고 버튼을 클릭하면 해고되어야합니다. 어디 imgBTNExportPPT에 대한 귀하의 aspx 코드? – Liam
''json'의'dataType'을 지정하고 있습니다 만, 호출중인 코드는 JSON 데이터를 반환하지 않습니다. 대신 다운로드 할 파일을 제공하는 것처럼 보입니다. 이 경우, 간단히'window.location.href = 'PEventPerformance.aspx/updateContent'; ' –
이전에 onclick을 사용하여 호출 한 적이 있었지만 .. 그 중 하나를 변경하는 것을 잊어 버렸습니다. 이제 그 중 하나를 고려하십시오. 함수로하고 그 중 하나를 아약스를 호출하는 방법을 말해 – nitinvertigo