Joh*_*ann 1 c# asp.net jquery json
我有以下WebMethod: -
[WebMethod(EnableSession = true)]
public static void OpenReport(string reportName)
{
Report report = reportsBll.GetReports().FirstOrDefault(x => reportQuestion != null && x.Id == reportQuestion.ReportId);
if (report != null) reportUrl = report.Url;
}
Run Code Online (Sandbox Code Playgroud)
现在我希望传递report.Url到这个Jquery方法: -
$('.ReportButton').click(function () {
var args = { reportName : '' };
$.ajax({
type: "POST",
url: "ReportsByQuestionsDetails.aspx/OpenReport",
data: JSON.stringify(args),
contentType: "application/json;charset=utf-8;",
success: function (data) {
alert('success');
document.location.href = reportUrl;
},
error: function () {
}
});
});
Run Code Online (Sandbox Code Playgroud)
如何将reportUrl从WebMethod传递给Jquery?
谢谢你的帮助和时间
您需要返回的string在C#方法:
[WebMethod(EnableSession = true)]
public static string OpenReport(string reportName)
{
string reportUrl = string.Empty;
Report report = reportsBll.GetReports().FirstOrDefault(x => reportQuestion != null && x.Id == reportQuestion.ReportId);
if (report != null) reportUrl = report.Url;
return reportUrl;
}
Run Code Online (Sandbox Code Playgroud)
然后在你的ajax返回Url中你可以做(你可能希望在报告为null时回退):
success: function (data) {
location.href = data;
},
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1543 次 |
| 最近记录: |