Export_ex'需要& # 39;1 & # 39;在asp.net c#中调用web服务时出现参数错误
本文关键字:服务 web 调用 错误 参数 asp ex 需要 net Export | 更新日期: 2023-09-27 18:01:47
我在asp .net c#中编写了一个web服务,当我从java脚本调用它时,我得到错误的方法'Export_ex'在调用web服务时需要'1'参数。
这里是javascript代码
function myF() {
var data = demo.innerHTML;
$.ajax({
type: "POST",
url: "WebService.asmx/Export_ex",
data: JSON.stringify(data),
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(response) {
var show = response.d;
alert(show);
// alert("success");
},
failure: function(msg) {
alert("Error occur, could not load the service.");
}
});
}
这是我的webservice方法
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public void Export_ex(string elem)
{
string elements = "elem";
HttpContext.Current.Response.ContentType = "data:application/vnd.ms-excel";
HttpContext.Current.Response.AddHeader("content-disposition", "attachment; filename=Print.xls");
HttpContext.Current.Response.Write("<html xmlns:x='"urn:schemas-microsoft-com:office:excel'">");
HttpContext.Current.Response.Write("<head>");
HttpContext.Current.Response.Write("<div>");
HttpContext.Current.Response.Write("<META http-equiv='"Content-Type'" content='"text/html; charset=utf- 8'">");
HttpContext.Current.Response.Write("<!--[if gte mso 9]><xml>");
HttpContext.Current.Response.Write("<x:ExcelWorkbook>");
HttpContext.Current.Response.Write("<x:ExcelWorksheets>");
HttpContext.Current.Response.Write("<x:ExcelWorksheet>");
HttpContext.Current.Response.Write("<x:Name>Report Data</x:Name>");
HttpContext.Current.Response.Write("<x:WorksheetOptions>");
HttpContext.Current.Response.Write("<x:ValidPrinterInfo/>");
HttpContext.Current.Response.Write("</x:Print>");
HttpContext.Current.Response.Write("</x:WorksheetOptions>");
HttpContext.Current.Response.Write("</x:ExcelWorksheet>");
HttpContext.Current.Response.Write("</x:ExcelWorksheets>");
HttpContext.Current.Response.Write("</x:ExcelWorkbook>");
HttpContext.Current.Response.Write("</xml>");
HttpContext.Current.Response.Write("<![endif]--> ");
HttpContext.Current.Response.Write("</head>");
HttpContext.Current.Response.Write(elements);
HttpContext.Current.Response.End(); ;
}
有人能帮忙吗?
您不应该将您的数据stringify
。(一路上会连载):
data: JSON.stringify(data),
应:data : data