在ASP .NET C#中调用Web服务时,方法'Export_ex'的重载不会出现'1'参数错误 - c#

当我从Java脚本调用ASP.NET C#时,我已经在Web服务中编写了Web服务,但收到错误消息:调用Web服务时,方法'Export_ex'的重载没有接受'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.");
            }
        });
    }

这是我的网络服务方法

[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

为什么使用'=='或'is'比较字符串有时会产生不同的结果? - python

我有一个Python程序,其中将两个变量设置为'public'值。在条件表达式中,我有比较var1 is var2失败,但如果将其更改为var1 == var2,它将返回True。现在,如果我打开Python解释器并进行相同的“是”比较,则此操作成功。>>> s1 = 'public' >>…

单行的'if'/'for'语句是否使用Python样式好? - python

我经常在这里看到某人的代码,看起来像是“单线”,这是一条单行语句,以传统的“if”语句或“for”循环的标准方式执行。我在Google周围搜索,无法真正找到可以执行的搜索类型?任何人都可以提出建议并最好举一些例子吗?例如,我可以一行执行此操作吗?example = "example" if "exam" in exam…

将字符串分配给numpy.zeros数组[重复] - python

This question already has answers here: Weird behaviour initializing a numpy array of string data                                                                    (4个答案)         …

如何修复AttributeError:模块'numpy'没有属性'square' - python

Improve this question 我已经将numpy更新为1.14.0。我使用Windows10。我尝试运行我的代码,但出现此错误: AttributeError:模块“ numpy”没有属性“ square”这是我的进口商品:%matplotlib inline import matplotlib.pyplot as plt import ten…

'ConfigurationBuilder'不包含'AddJsonFile'的定义 - c#

我有以下错误:Program.cs(15,72):错误CS1061:“ ConfigurationBuilder”不包含“ AddJsonFile”的定义,并且找不到包含“ ConfigurationBuilder”类型的第一个参数的可访问扩展方法“ AddJsonFile”(您是否缺少使用指令或汇编该项目是一个使用Azure Search SDK的dotn…