我使用jquery dataTable和服务器端处理数据。我使用asp.net web方法进行服务器端处理。我有2个web方法让我们称它为WebMethod1'和#WebWeethod2'和2个按钮' Button1'和' Button2'当我点击Button1时,我想从WebMethod1调用数据,当我点击Button2时,我想从WebMethod2调用数据
HTML
<button type="button" class="data-search" data-Get="Members" id="btnMemberSearch">Button1</button>
<button type="button" class="data-search" data-Get="Accounts" id="btnAccountSearch">Button1</button>
<table class="table table-hover" style="width:100%;" id="tblSearchList">
<thead id="tblSearchHead">
</thead>
</table>
Jquery的
var columns='';
var tr='';
var functionName ='';
$(".member-search").click(function (e) {
e.preventDefault();
var searchfor = $(this).attr('data-Get');
if (searchfor == 'Members') {
tr = '<tr><th>MemberNo</th><th>Name</th><th>FatherName</th><th>Mobile</th><th>CitizenshipNo</th></tr>';
functionName = 'WebMethod1';
columns = [
{ data: "MemberNo" },
{ data: "Name" },
{ data: "FatherName" },
{ data: "Mobile" },
{ data: "CitizenshipNo" }];
}
else if (searchfor == 'Accounts) {
tr = '<tr><th>AccountNo</th><th>Name</th><th>MemberNo</th><th>Product</th></tr>';
functionName = 'WebMethod2';
columns = [{ data: "AccountNo" },
{ data: "Name" },
{ data: "MemberNo" },
{data:"Product"}
]
}
$('#tblSearchHead').children().remove();
$('#tblSearchHead').append(tr);
ajaxSource = '../Main/MemAndAcSearch.asmx/'+functionName;
table = $('#tblSearchList').DataTable({
bServerSide: true,
retrieve: true,
columns:columns,
sAjaxSource: ajaxSource,
sServerMethod: 'post',
bProcessing: true
}
});
});
这里的问题是ajaxsource没有被刷新或重新加载。从我点击的第一个按钮加载页面后,相同的Webmethod被调用,直到我重新加载页面。例如,在加载页面后如果我单击Button1,则每次调用WebMethod1,即使我单击Button2,如果我重新加载页面,则单击Button2,然后每次调用WebMethod2。
我如何重新加载我的ajax源。?
答案 0 :(得分:0)
更改按钮ID,因为DOM ID在创建和操作DOM方面起着至关重要的作用。
<button type="button" class="data-search" data-Get="Members" id="btnNomineeAcMembersSearch">Button1</button>
<button type="button" class="data-search" data-Get="Accounts" id="btnNomineeAcSearch">Button2</button>