jQuery-使用POST请求,这是不允许的错误 [英] Jquery - using a POST request, which is not allowed Error
本文介绍了jQuery-使用POST请求,这是不允许的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试让jquery与Web服务通信!
I am trying to get jquery to communicate with a web service!!
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 = true
的ScriptMethodAttribute
.尝试删除此参数,或将其设置为false
.这就是阻止POST正常工作的原因.
Your web service method is marked with a ScriptMethodAttribute
that specifies UseHttpGet = true
. Try removing this argument, or setting it to false
. This is what is preventing the POST from working.
这篇关于jQuery-使用POST请求,这是不允许的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文