我是jquery的新成员ajax.i想调用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中使用FireBug按F12)查看正在请求并返回的内容?你有没有看过错误细节? – Corey 2013-05-02 05:27:18
无法加载资源:服务器响应状态为500(内部服务器错误)我在Web浏览器中出现此错误。 – 2013-05-02 05:37:18
通常这是因为您的代码中引发了异常。尝试直接浏览Web服务URL并查看是否收到异常跟踪消息。另外,请尝试调试Web服务,并在'GetInceDed'方法的开头添加一个断点。 – Corey 2013-05-02 05:46:50