Javascript Ajax post到Asmx中缺少参数
我正在尝试将字符串Javascript Ajax post到Asmx中缺少参数,javascript,jquery,ajax,web-services,asmx,Javascript,Jquery,Ajax,Web Services,Asmx,我正在尝试将字符串文件发送到我的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.
文件发送到我的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\"}
这是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
});
}
当传递到上述函数中时,文件
的值为“test\r\n”,转义字符是否会弄乱它
服务代码
[WebMethod(EnableSession = true)]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public bool UploadCSV(string id, string File)
{
string testfile = File;
return true;
}
不会抛出其他错误,只是文件
没有值。
我尝试了各种方法,但无法理解我缺少了什么?尝试将数据作为普通对象发送:
data: { 'File': File },
或作为字符串:
data: 'File=' + File,
目前,你正在做的两件事都有一点行不通。著名的@Rory McCrossan+1:)谢谢你的快速回复!“data:{'File':File}”抛出无效的JSON基元异常“data:'File='+File”与数据类型文本完美结合!我猜我的JSON格式不正确或引用不正确,thanks@Rory我有同样的错误,但我有三个变量,我要用一个“&”来连接它们吗