缺少Ajax中的参数发布到Asmx

Ale*_*lex 3 javascript ajax jquery web-services asmx

我正在尝试将字符串发送File到我的asmx服务,并且我不断收到以下错误:

    Message: Invalid web service call, missing value for parameter: File
    StackTrace   
at System.Web.Script.Services.WebServiceMethodData.CallMethod(Object target, IDictionary`2 parameters) at 
System.Web.Script.Services.WebServiceMethodData.CallMethodFromRawParams(Object target, IDictionary`2 parameters)\\r\\n   at 
System.Web.Script.Services.RestHandler.InvokeMethod(HttpContext context, WebServiceMethodData methodData, IDictionary`2 rawParams)\\r\\n   at 
System.Web.Script.Services.RestHandler.ExecuteWebServiceCall(HttpContext context, WebServiceMethodData methodData)\",\"ExceptionType\":\"System.InvalidOperationException\"}
Run Code Online (Sandbox Code Playgroud)

这是JS

function AJAXActionPostData(service, operation, File, callback, async)
{
    if (!async) { async = false; }
    $.ajax({
        type: 'POST',
        url: '/API/Service.asmx/operation',
        contentType: 'application/json; charset=utf-8',
        async: async,
        data: "{ 'File': '" + File + "' }",
        dataType: 'json',
        success: function (msg) { if (msg) { callback(msg.d); } },
        error: ErrorHandler
    });
}
Run Code Online (Sandbox Code Playgroud)

当传入上面的函数时,file其值为"test\r \n",转义字符是否可以搞乱?

服务代码

    [WebMethod(EnableSession = true)]
    [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
    public bool UploadCSV(string id, string File)
    {
        string testfile = File;
        return true;
    }
Run Code Online (Sandbox Code Playgroud)

没有其他错误被抛出,只是File没有值.我尝试过各种各样的东西,却无法理解我所缺少的东西?

Ror*_*san 5

尝试将其data作为普通对象发送:

data: { 'File': File },
Run Code Online (Sandbox Code Playgroud)

或者作为一个字符串:

data: 'File=' + File,
Run Code Online (Sandbox Code Playgroud)

目前你正在做一些不起作用的事情.