버튼을 사용하여 두 번의 AJAX 호출을 수행하려고합니다. Button1을 클릭하면 ProductsTable이 웹 서비스의 데이터를 보여줍니다. Button2를 클릭하면 OtherTable이 웹 서비스의 자체 데이터를 보여줍니다. 그러나 지금 당장 버튼 하나를 클릭하면 아무 것도 나타나지 않습니다. 나는 그 중 하나만 있다면 코드가 작동하고 .click 함수를 감싸고 있지 않다는 것을 안다.JQuery에서 여러 개의 AJAX 호출을 개별적으로 수행하는 방법
오류 메시지가 없습니다. ASP.NET 4.0, JQuery 1.4.4. ScriptManager를 사용하지 않습니다. UpdatePanels를 사용하지 않습니다. 아래
코드 :
<script src="Scripts/jquery-1.4.4.js" type="text/javascript"></script>
<script src="Scripts/jquery.tmpl.js" type="text/javascript"></script>
<script id="ProductsTemplate" type="text/x-query-tmpl">
<tables id="ProductsTemplate">
<thead>
</thead>
<tbody>
{{each d}}
{{tmpl($value) '#ProductsRowTemplate'}}
{{/each}}
</tbody>
</tables>
</script>
<script id="ProductsRowTemplate" type="text/x-query-tmpl">
<tr>
<td>${title}</td>
<td>${size}</td>
<td>${price}</td>
</tr>
</script>
<script id="Products2Template" type="text/x-query-tmpl">
<tables id="Products2Template">
<thead>
</thead>
<tbody>
{{each d}}
{{tmpl($value) '#Products2RowTemplate'}}
{{/each}}
</tbody>
</tables>
</script>
<script id="Products2RowTemplate" type="text/x-query-tmpl">
<tr>
<td>${title}</td>
<td>${size}</td>
<td>${price}</td>
</tr>
</script>
<script type="text/javascript">
$(document).ready(function() {
$("#Button1").click(function() {
$.ajax({
type: "POST",
url: "JSON-WebService.asmx/getProducts",
data: "{}",
contentType: "application/json; charset=UTF-8",
dataType: "json",
success: function (data) {
$('#ProductsTemplate').tmpl(data).appendTo('#ProductsTable');
alert("Products works");
},
failure: function (data) {
alert("Products didn't work");
}
});
});
$("#Button2").click(function() {
$.ajax({
type: "POST",
url: "JSON-WebService.asmx/getProducts",
data: "{}",
contentType: "application/json; charset=UTF-8",
dataType: "json",
success: function (data) {
$('#Products2Template').tmpl(data).appendTo('#OthersTable');
alert("Products2 works");
},
failure: function (data) {
alert("Products2 didn't work");
}
});
});
});
</script>
<title>Using JQuery</title>
<form id="form1" runat="server">
<div id="ProductsTable">
</div>
<div id="OthersTable">
</div>
<div>
<asp:Button ID="Button1" runat="server" Text="Products" />
<asp:Button ID="Button2" runat="server" Text="Products2" />
</div>
</form>
이 이상해, 우리는 페이지에 많은 아약스 reqeusts을 가질 수 대답은 사용하는 것입니다 백엔드의 중단 점 – kobe
클릭 한 후에 요청이 진행되고 있지만 그게 전부입니다. 내 구문이 잘못 되었습니까? – dotnetN00b
렌더링 된 HTML 모양이 해당 단추와 어떤 차이가 있습니까? –