gpt4 book ai didi

Jquery - 使用 POST 请求,这是不允许的错误

转载 作者:行者123 更新时间:2023-12-03 22:35:20 27 4
gpt4 key购买 nike

我正在尝试让 jquery 与网络服务进行通信!!

  function Test(item) {
$.ajax({
type: 'POST',
url: 'WebService.asmx/Test',
data: '{ "Item" : "' + item + '" }',
contentType: 'application/json; charset=utf-8',
dataType: 'json',
success: function (msg) {
alert("oi");
},
error: function (msg) {
alert('Get Details Failure: ' + msg);
}
});
};

using System.Web;
using System.Web.Services;
using System.Data.SqlClient;
using System.Web.Script.Services;
using System.Web.Script.Serialization;

[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
[ScriptService]
public class WebService : System.Web.Services.WebService {

public WebService () {}

[System.Web.Services.WebMethod]
[System.Web.Script.Services.ScriptMethod(UseHttpGet = true, ResponseFormat = System.Web.Script.Services.ResponseFormat.Json)]
public string Test(string Item)
{
JavaScriptSerializer js = new JavaScriptSerializer();
string strJSON = js.Serialize(Item);
return strJSON;
}

我收到以下消息:

{"Message":"An attempt was made to call the method \u0027Test\u0027 using a POST request, which is not allowed.","StackTrace":"   at System.Web.Script.Services.RestHandler.GetRawParams(WebServiceMethodData methodData, HttpContext context)\r\n   at System.Web.Script.Services.RestHandler.ExecuteWebServiceCall(HttpContext context, WebServiceMethodData methodData)","ExceptionType":"System.InvalidOperationException"}

最佳答案

您的 Web 服务方法标有指定 UseHttpGet = trueScriptMethodAttribute。尝试删除此参数,或将其设置为 false。这就是阻止 POST 工作的原因。

关于Jquery - 使用 POST 请求,这是不允许的错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8883555/

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