【发布时间】:2014-10-17 04:06:57
【问题描述】:
我尝试使用以下 ajax 方法调用 webservice 方法。 但是我无法使用 AJAX 调用访问 Webservice 方法。Web 服务将在 ajax 成功中返回 JSON 字符串。
提前致谢。
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication1.WebForm1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script src="jquery-1.11.0.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
alert('invoke1')
$("#testbtn").click(function () {
alert('btnclick')
$.ajax({
type: "Post",
url: "WebService.asmx/GetAllRecords",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
var Employees = data.d;
$('#grddata').empty();
for (var i = 0; i < Employees.length; i++) {
if (i == 0) {
$('#grddata').append('<table><tr><td><strong>Emp_Title:</strong></td><td>' + Employees[i] + '</td></tr>');
}
else if (i % 2) {
$('#grddata').append('<tr><td><strong> Emp_Name:</strong> </td><td>' + Employees[i] + '</td></tr>');
}
else {
$('#grddata').append('<table><tr><td><strong>Emp_Title:</strong></td><td>' + Employees[i] + '</td></tr>');
}
}
},
failure: function (data) {
alert("Error Ha..Ha...Ha...");
}
});
})
});
</script>
</head>
<body>
<form id="form1" runat="server">
<input type="button" onclick="BindGridView()" id="testbtn"/>
<div id="grddata">
</div>
</form>
</body>
</html>
【问题讨论】:
-
控制台中的任何错误
-
@ArunPJohny got Bindgridview() is not defined 错误
标签: javascript c# jquery ajax web-services