gpt4 book ai didi

c# - Javascript - jquery ajax 发布错误让我发疯

转载 作者:行者123 更新时间:2023-11-30 15:10:43 25 4
gpt4 key购买 nike

似乎无法弄清楚这一点。

我有一个定义为 (c#,.net) 的 Web 服务

[WebMethod]
public string SubmitOrder(string sessionid, string lang,int invoiceno,string email,string emailcc)
{
//do stuff.
return stuff;
}

当我在 Vstudio 中通过自动生成的测试工具对其进行测试时,效果很好。

但是当我从 jquery 调用它时

$j.ajax({
type: "POST",
url: "/wservice/baby.asmx/SubmitOrder",
data: "{'sessionid' : '"+sessionid+"',"+
"'lang': '"+usersettings.Currlang+"',"+
"'invoiceno': '"+invoicenr+"',"+
"'email':'"+$j(orderids.txtOIEMAIL).val()+"',"+
"'emailcc':'"+$j(orderids.txtOICC).val()+"'}",
contenttype: "application/json; charset=utf-8",
datatype: "json",
success: function (msg) {
submitordercallback(msg);
},
error: AjaxFailed
});

我得到了这个有趣的错误:

responseText: System.InvalidOperationException: Missing parameter: sessionid.    at  System.Web.Services.Protocols.ValueCollectionParameterReader.Read(NameValueCollection collection)    at  System.Web.Services.Protocols.HtmlFormParameterReader.Read(HttpRequest request)    at  System.Web.Services.Protocols.HttpServerProtocol.ReadParameters()    at  System.Web.Services.Protocols.WebServiceHandler.CoreProcessRequest()  

data evaluates to: {'sessionid' : 'f61f8da737c046fea5633e7ec1f706dd','lang': 'SE','invoiceno': '11867','email':'steve@jobs.com','emailcc':''}

Ok, fair enough, but this function from jquery communicates fine with another webservice.

Defined:

c#:

[WebMethod]
public string CheckoutClicked(string sessionid,string lang)
{
//*snip*

//jquery:

var divCheckoutClicked = function()
{
$j.ajax({
type: "POST",
url: "/wservice/baby.asmx/CheckoutClicked",
data: "{'sessionid': '"+sessionid+"','lang': '"+usersettings.Currlang+"'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (msg) {
divCheckoutClickedCallback(msg);
},
error: AjaxFailed
});
}

最佳答案

data: {sessionid: sessionid,
lang: usersettings.Currlang,
invoiceno: invoicenr,
email: $j(orderids.txtOIEMAIL).val(),
emailcc: $j(orderids.txtOICC).val()
},

关于c# - Javascript - jquery ajax 发布错误让我发疯,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3020351/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com