gpt4 book ai didi

jquery - 出现500错误

转载 作者:行者123 更新时间:2023-12-01 02:59:34 25 4
gpt4 key购买 nike

我正在使用JQuery和Ajax与ASP.Net Web服务进行接口。这是Jquery代码:

$.jrpc = function(url, id, method, params, success, error) {
var request = $.json_stringify({
'jsonrpc': '2.0', 'method': method,
'params': params, 'id': id});
return $.ajax({
url: url,
data: "json=" + encodeURIComponent(request),
success: success,
error: error,
contentType: 'application/json; charset=utf-8',
dataType: 'json',
async: true,
cache: false,
//timeout: 1,
type: 'POST'});
};


这是Web服务代码:

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

[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public string EntryMethod(string json)
{
Requests d = JsonConvert.DeserializeObject<Requests>(json);
Response resp = new Response();
resp.jsonrpc = d.jsonrpc;
resp.result = "Got the call!";
resp.id = d.id;
resp.error = null;
JavaScriptSerializer response = new JavaScriptSerializer();
string r = response.Serialize(resp);

return r;
}
}


我收到此错误:

[AJAX]错误-服务器响应为:
{“ Message”:“无效的JSON原语:json。”,“ StackTrace”:“在System.Web.Script.Serialization.JavaScriptObjectDeserializer.DeserializePrimitiveObject()\ r \ n在System.Web.Script.Serialization.JavaScriptObjectDeserializer.DeserializeInternal( Int32深度)\ r \ n在System.Web.Script.Serialization.JavaScriptObjectDeserializer.BasicDeserialize(字符串输入,Int32 depthLimit,JavaScriptSerializer序列化器)\ r \ n在System.Web.Script.Serialization.JavaScriptSerializer.Deserialize(JavaScriptSerializer序列化器,字符串输入,类型类型,Int32 depthLimit)\ r \ n在System.Web.Script.Serialization.JavaScriptSerializer.Deserialize [T](字符串输入)\ r \ n在System.Web.Script.Services.RestHandler.GetRawParamsFromPostRequest(HttpContext context) ,JavaScriptSerializer序列化程序)\ r \ n在System.Web.Script.Services.RestHandler.GetRawParams(WebServiceMethodData methodData,HttpContext上下文)\ r \ n在System.Web.Script.Services.RestHandler.ExecuteWebServiceCall(HttpContext上下文,WebServiceMetho dData methodData)“,” ExceptionType“:” System.ArgumentException“}

使用ASP.Net Web服务测试页,这是我的标题和请求字符串:
缓存控制:私有,最大年龄= 0
日期:2012年10月3日,星期三19:47:16 GMT
内容长度:149
内容类型:text / xml;字符集= utf-8
服务器:ASP.NET开发服务器/10.0.0.0
X-AspNet版本:4.0.30319
连接:关闭

json =%7B%22jsonrpc%22%3A%222.0%22%2C%22method%22%3A%22test%22%2C%22params%22%3A%5B%5D%2C%22id%22%3A1%7D

这是我的Ajax调用的标头/请求字符串,它不起作用:
缓存控制:私有
日期:2012年10月3日,星期三19:47:09 GMT
内容长度:1062
内容类型:application / json;字符集= utf-8
jsonerror:是
服务器:ASP.NET开发服务器/10.0.0.0
X-AspNet版本:4.0.30319
连接:关闭

json =%7B%22jsonrpc%22%3A%222.0%22%2C%22method%22%3A%22test%22%2C%22params%22%3A%5B%5D%2C%22id%22%3A1%7D

关于我为什么会收到此错误的任何想法?我已经尝试过使用Google搜索,但没有任何结果真正对我有所帮助。

编辑:

如果我使用:
数据:“ {'jsonrpc':'2.0','方法':'test','参数':[],'id':1}”,

我收到此错误:
[AJAX]错误-服务器响应为:
{“ Message”:“无效的Web服务调用,缺少参数值:\ u0027json \ u0027。”,“ StackTrace”:“位于System.Web.Script.Services.WebServiceMethodData.CallMethod(对象目标,IDictionary 2 parameters)\r\n at System.Web.Script.Services.WebServiceMethodData.CallMethodFromRawParams(Object target, IDictionary 2个参数)\ r \ n在System.Web.Script.Services.RestHandler.InvokeMethod(HttpContext上下文,WebServiceMethodData methodData,IDictionary`2 rawParams)\ r \ n在System.Web.Script.Services.RestHandler.ExecuteWebServiceCall(HttpContext上下文,WebServiceMethodDataData methodData)“,” ExceptionType“:” System.InvalidOperationException“}

如果我使用:
数据:“ json = {'jsonrpc':'2.0','method':'test','params':[],'id':1}“,

我收到此错误:
[AJAX]错误-服务器响应为:
{“ Message”:“无效的JSON原语:json。”,“ StackTrace”:“在System.Web.Script.Serialization.JavaScriptObjectDeserializer.DeserializePrimitiveObject()\ r \ n在System.Web.Script.Serialization.JavaScriptObjectDeserializer.DeserializeInternal( Int32深度)\ r \ n在System.Web.Script.Serialization.JavaScriptObjectDeserializer.BasicDeserialize(字符串输入,Int32 depthLimit,JavaScriptSerializer序列化器)\ r \ n在System.Web.Script.Serialization.JavaScriptSerializer.Deserialize(JavaScriptSerializer序列化器,字符串输入,类型类型,Int32 depthLimit)\ r \ n在System.Web.Script.Serialization.JavaScriptSerializer.Deserialize [T](字符串输入)\ r \ n在System.Web.Script.Services.RestHandler.GetRawParamsFromPostRequest(HttpContext context) ,JavaScriptSerializer序列化程序)\ r \ n在System.Web.Script.Services.RestHandler.GetRawParams(WebServiceMethodData methodData,HttpContext上下文)\ r \ n在System.Web.Script.Services.RestHandler.ExecuteWebServiceCall(HttpContext上下文,WebServiceMetho dData methodData)“,” ExceptionType“:” System.ArgumentException“}

最佳答案

更改
数据:“ json =” + encodeURIComponent(request),

数据:“ {json:'” + encodeURIComponent(request)+“'}”,

查看示例代码

  $.ajax("WebService.asmx/EntryMethod", {
contentType: "application/json; charset=utf-8",dataType: "json",
type: "POST", data: "{json:'value'}", success: function (r) { alert(r); },
error: function (e) { alert(e); }
});

关于jquery - 出现500错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12715958/

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