2番目のajax呼び出しのwebmethod(SaveSalaryDetails)が断続的に呼び出されることはありません。私がjavascript/jqueryをデバッグしている場合、それは起動されます。ファイルの後ろjqueryの別のajax呼び出し内のajax呼び出しが断続的に起動しない
function fnCheckAndSaveSalary() {
debugger;
var salary = document.getElementById(" <%=txtSelEmployeeSalary.ClientID %>").value;
var employeeID = $find("<%=rcmbEmployees.ClientID %>").get_value();
var employeeName = $find("<%=rcmbEmployees.ClientID %>").get_text();
var paidDate = $find("<%=radPayDate.ClientID %>").get_selectedDate();
//var lblStatus = document.getElementById("<%=lblStatus.ClientID %>");
//setTimeout(saveSalary, 15000);
$.ajax({
type: 'POST',
contentType: 'application/json;charset=utf-8',
datatype: 'json',
data: JSON.stringify({ EmpID: employeeID, PaidDate: paidDate }),
url: 'Pay.aspx/IsSalaryExisting',
success: function(response) {
debugger;
alert("Checked for records" + response.d);
//debugger;
//No record exists for the particular month and year for the employee
if (response.d == false) {
debugger;
alert("Now saving..");
saveSalary(salary, employeeID, paidDate);
}
else {
//debugger;
alert('Salary already exists for Employee:' + employeeName + ' for date:' + paidDate);
}
},
failure: function(response) {
alert(response.d);
}
});
}
function saveSalary(salary, employeeID, paidDate) {
$.ajax({
type: 'POST',
contentType: 'application/json;charset=utf-8',
datatype: 'json',
data: JSON.stringify({ Salary: salary, EmpID: employeeID, PaidDate: paidDate }),
url: 'Pay.aspx/SaveSalaryDetails',
success: function(response) {
//debugger;
alert('Successfully saved');
},
failure: function(response) {
alert('Error in saving the salary details' + response.d);
}
});
}
<form id="form1" runat="server">
<telerik:RadScriptManager runat="server" ID="RadScriptManager1" />
<div>
<table>
<tr>
<td>Select Employee:</td>
<td><telerik:RadComboBox ID="rcmbEmployees" runat="server" OnSelectedIndexChanged="rcmbEmployees_SelectedIndexChanged" AutoPostBack="true"></telerik:RadComboBox>
</td>
</tr>
<tr>
<td>Salary: </td>
<td><asp:TextBox ID="txtSelEmployeeSalary" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>Pay Date:</td>
<td><telerik:RadMonthYearPicker ID="radPayDate" runat="server"
MinDate="1/1/2000" MaxDate="1/1/3000"></telerik:RadMonthYearPicker></td>
</tr>
</table>
<asp:Button ID="btnSave" runat="server" Text="Save" OnClientClick="fnCheckAndSaveSalary()" />
<asp:Label ID="lblStatus" runat="server"></asp:Label>
</div>
</form>
コード:以下のコードである
[WebMethod]
public static int SaveSalaryDetails(string Salary, string EmpID, string PaidDate)
{
//saves details in the database and returns ID
}
catch (Exception ex)
{
throw ex;
}
return objEmpSalaryObj.PaymentID;
}
[WebMethod]
public static bool IsSalaryExisting(string EmpID, string PaidDate)
{
EmployeeController objController = new EmployeeController();
EmployeePayHistoryVo objEmpSalaryObj = new EmployeePayHistoryVo();
bool salaryExists = false;
try
{
objEmpSalaryObj.EmployeeID = Convert.ToInt32(EmpID);
objEmpSalaryObj.PaidMonth = (Convert.ToDateTime(PaidDate)).ToString("MMMM");
objEmpSalaryObj.PaidYear = (Convert.ToDateTime(PaidDate)).Year;
salaryExists = objController.IsSalaryExisting(objEmpSalaryObj);
//System.Threading.Thread.Sleep(1000);
}
catch (Exception ex)
{
throw ex;
}
return salaryExists;
}
は、あなたが "今すぐ節約" のアラートを取得しているが、それが呼び出されていなくても?ブラウザのコンソールにエラーがありますか? – Rhumborl
いいえ、コンソールにエラーはありません。私は警報も出さない。 – Karts
基本的には、2つのメソッドを1つにまとめることができます。 –