【发布时间】:2016-04-13 23:42:00
【问题描述】:
我正在尝试将字符串发布到网络服务,但出现此错误(Google Chrome 扩展项目):
jquery-2.1.1.min.js:4 POST http://localhost:49242/Service.asmx/test 500(内部服务器错误)
这是我的 ajax 代码:
var data = {};
data.param1 = words[0];
$.ajax({
data: JSON.stringify({ 'data': data.param1 }),
dataType: 'application/json',
url: 'http://localhost:49242/Service.asmx/test',
type: 'POST',
contentType: 'application/json; charset=utf-8',
success: function (result) {
alert(result);
},
failure: function (errMsg) {
alert(errMsg);
}
});
我的服务:
[WebMethod]
[System.Web.Script.Services.ScriptMethod(ResponseFormat = System.Web.Script.Services.ResponseFormat.Json)]
public string test(string param1) {
return param1;
}
我正在处理这个问题大约 3 天。你能帮助我吗 ?
顺便说一句,我有一个问题。我正在使用 ajax 将 json 变量发布到服务(如您所见),但服务返回 xml 值。有问题还是[System.Web.Script.Services.ScriptMethod(ResponseFormat = System.Web.Script.Services.ResponseFormat.Json)]这个代码块解决问题?
【问题讨论】:
-
在数据类型中写入
json -
谢谢,但没用。
-
您是否检查过您的 url 正在处理您发布的数据?
-
尽量不要对您的数据进行字符串化?数据:{ param1:'yourval'}
-
对不起,你为什么要删除你最后的帖子?
标签: javascript jquery ajax web-services google-chrome-extension