【发布时间】:2013-05-02 04:50:00
【问题描述】:
我是 jquery ajax 的新手。我想调用 Web 服务但不工作。 这是我的 jquery 代码。
$(document).ready(function () {
$('#TxBx_BasicSalary').focusout(function () {
var EmployeeId = $('#Hid_EmpID').val();
$.ajax({
type: "POST",
cache: false,
contentType: "application/json; charset=utf-8",
url: '/WebService/IncDedWebService.asmx/GetInceDed',
data: JSON.stringify({ id: EmployeeId }),
dataType: 'json',
success: function (data) {
alert("")
},
error: function () { alert("error"); }
});
});
这是 WebService 方法。
[WebMethod]
[ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)]
public string GetInceDed(int id)
{
ClsSalary salary = new ClsSalary();
//var abc salary=.GetIncDedByEmpId(id);
var serializer = new JavaScriptSerializer();
var json = serializer.Serialize(salary.GetIncDedByEmpId(id));
return json;
}
这在我调用时不起作用。它执行错误部分。 请帮助我。我做错了什么。
【问题讨论】:
-
您是否使用过浏览器中的开发者工具(在 IE、Chrome 或 Firefox-with-FireBug 中按 F12)查看请求和返回的内容?您是否查看过错误详细信息?
-
加载资源失败:服务器响应状态为 500(内部服务器错误)我在 Web 浏览器中收到此错误。
-
这通常是因为您的代码中抛出了异常。尝试直接浏览到 Web 服务 URL 并查看是否收到异常跟踪消息。另外,尝试调试 Web 服务并在
GetInceDed方法的开头放置一个断点。 -
web 服务方法没有被断点击中。当我在方法开始时超过断点。
标签: c# web-services jquery