我正在尝试调用Web服务并始终收到错误,警报错误显示“未定义”
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public static string Test()
{
JavaScriptSerializer js = new JavaScriptSerializer();
return js.Serialize("Hello");
}
这是脚本
$.ajax({ type: "POST",
contenttype: "application/json; charset=utf-8",
data: "{}",
url: "WorkflowAjaxHelper.asmx/Test",
dataType: "json",
async: false,
success: function (res) {
alert('success');
},
error: function (err) {
alert(err.text);
}
});
答案 0 :(得分:1)
文本在错误对象上无效。您可以使用以下任何一项来获取更多信息:
responseText
status
statusText
利用Chrome,IE或Firefox中内置的调试器来帮助调试。你也可以在console.log中找到一个对象,chrome和firefox非常适合让你点击对象模型看看有什么可用。
答案 1 :(得分:0)
.asmx.cs文件的顶部是否具有以下属性,Jorge?
/// <summary>
/// Summary description for PartServices
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
// This bit here!!!
[System.Web.Script.Services.ScriptService]
public class PartServices : System.Web.Services.WebService