在阿贾克斯后缺少参数ASMX [英] Missing parameter in Ajax post to Asmx

查看:1107
本文介绍了在阿贾克斯后缺少参数ASMX的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想字符串文件发到我的ASMX服务,我不断收到以下错误:

I'm trying to send the string File to my asmx service and I keep getting the following error:

    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\"}

这里的JS

Here's the 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
    });
}

在上述传递给函数的文件有测试\ r \ N可能转义字符来捣乱呢?

when passed into the function above file has a value of "test\r\n" Could the escape characters be messing with it?

服务code

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

没有其他错误抛出,就在文件不具有价值。 我已经试过各种东西,但无法理解,我缺少的是什么?

No other errors are thrown, just the File not having a value. I've tried various things but cannot understand what I'm missing?

推荐答案

试着发送了数据作为一个普通的对象:

Try sending the data as a plain object:

data: { 'File': File },

或字符串:

data: 'File=' + File,

目前你正在做一个小两个这是行不通的。

At the moment you're doing a little of both which won't work.

这篇关于在阿贾克斯后缺少参数ASMX的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆