Ajex
##——————————————-
$(document).ready(function () {
$("#searchWorkingStandardNo").autocomplete({
source: function (request, response) {
$.ajax({
url: "/WorkingStandardSet/GetWorkingStandardNo",
type: "POST",
dataType: "json",
data: { Prefix: request.term },
success: function (data) {
response($.map(data, function (item) {
return item;
}))
}
})
},
messages: {
noResults: 'No results found.',
results: function (count) {
return count + (count > 1 ? ' results' : ' result ') + ' found';
}
},
});
})
$(function () {
AjaxCall('/Controler/GetDepartment', null).done(function (response) {
if (response.length > 0) {
$('#searchDepartmentId').html('');
var options = '';
options += '<option value="Select">Select Department</option>';
for (var i = 0; i < response.length; i++) {
options += '<option value="' + response[i].val + '">' + response[i].label + '</option>';
}
$('#searchDepartmentId').append(options)
}
}).fail(function (error) {
alert(error.StatusText);
});
$('#searchDepartmentId').on("change", function () {
var department = $('#searchDepartmentId').val();
var obj = { department: department };
AjaxCall('/Controler/GetWSType', JSON.stringify(obj), 'POST').done(function (response) {
if (response.length > 0) {
$('#searchWorkingStandardTypeId').html('');
var options = '';
options += '<option value="Select">Select WS Type</option>';
for (var i = 0; i < response.length; i++) {
options += '<option value="' + response[i].val + '">' + response[i].label + '</option>';
}
$('#searchWorkingStandardTypeId').append(options);
}
else {
$('#searchWorkingStandardTypeId').html('');
}
}).fail(function (error) {
//alert(error.StatusText);
$('#searchWorkingStandardTypeId').html('');
});
});
$('#searchWorkingStandardTypeId').on("change", function () {
var wstype = $('#searchWorkingStandardTypeId').val();
var department = $('#searchDepartmentId').val();
var obj = { wstype: wstype };
AjaxCall('/Controler/GetWSProcess', JSON.stringify(obj), 'POST').done(function (response) {
if (response.length > 0) {
$('#searchWorkingStandardProcessId').html('');
var options = '';
options += '<option value="Select">Select WS Process</option>';
for (var i = 0; i < response.length; i++) {
options += '<option value="' + response[i].val + '">' + response[i].label + '</option>';
}
$('#searchWorkingStandardProcessId').append(options);
}
else {
$('#searchWorkingStandardProcessId').html('');
}
}).fail(function (error) {
//alert(error.StatusText);
$('#searchWorkingStandardProcessId').html('');
});
});
});
function AjaxCall(url, data, type) {
return $.ajax({
url: url,
type: type ? type : 'GET',
data: data,
contentType: 'application/json'
});
}
##——————————————————–
$(function () {
AjaxCall('/EmployeeFormer/GetUser', null).done(function (response) {
if (response.length > 0) {
var html = '';
for (var i = 0; i < response.length; i++) {
html += "<tr id='" + response[i].id + "'>";
html += "<td> <input type='radio' class='selectedItem' name='selectedItem' id='selectedItem' value='" + response[i].id + "' /> </td>";
html += '<td>' + (i+1) + '</td>';
html += '<td>' + response[i].fname + '</td>';
html += '<td>' + response[i].lname + '</td>';
html += '<td>' + response[i].email + '</td>';
html += '</tr>';
}
$('#ttbody').html(html);
}
}).fail(function (error) {
alert(error.StatusText);
});
$('#searchDepartmentId').on("change", function () {
var dept_id = $('#searchDepartmentId').val();
var obj = { dept_id: dept_id };
AjaxCall('/EmployeeFormer/GetUser', JSON.stringify(obj), 'POST').done(function (response) {
if (response.length > 0) {
var html = '';
for (var i = 0; i < response.length; i++) {
html += "<tr class='ttr' id='" + response[i].id + "'>";
html += "<td> <input type='radio' class='selectedItem' name='selectedItem' id='selectedItem' value='" + response[i].id + "' /> </td>";
html += '<td>' + (i+1) + '</td>';
html += '<td>' + response[i].fname + '</td>';
html += '<td>' + response[i].lname + '</td>';
html += '<td>' + response[i].email + '</td>';
html += '</tr>';
}
$('#ttbody').html(html);
}
else {
$('#ttbody').html('');
}
}).fail(function (error) {
//alert(error.StatusText);
});
});
});
function AjaxCall(url, data, type) {
return $.ajax({
url: url,
type: type ? type : 'GET',
data: data,
contentType: 'application/json'
});
}
$('#table1').click(function () {
/*
var row = $(this).closest('tr');
//var status = row.find("input:radio[name=selectedItem]:checked").val();
var name = row.find("td:eq(2)").html().trim();
var lname = row.find("td:eq(3)").html().trim();
var email = row.find("td:eq(4)").html().trim();
var emailTo = document.getElementById("emailTo");
var nameTo = document.getElementById("nameTo");
emailTo.innerHTML = "<h4>To: " + email + "</h4>";
nameTo.innerHTML = "<h4>Dear K' " + name + " " + lname + "</h4>";
*/
var se = document.getElementById("emailTo");
var emailTo = document.getElementById("emailTo");
var nameTo = document.getElementById("nameTo");
var name = " ";
var lname = " ";
var email = " ";
var grid = document.getElementById("table1");
var checkBoxes = grid.getElementsByClassName("selectedItem");
for (var i = 0; i < checkBoxes.length; i++) {
if (checkBoxes[i].checked) {
var row = checkBoxes[i].parentNode.parentNode;
var col2 = row.cells[2];
var col3 = row.cells[3];
var col4 = row.cells[4];
name = col2.innerText;
lname = col3.innerText;
email = col4.innerText;
}
}
emailTo.innerHTML = "<h4>To: " + email + "</h4>";
nameTo.innerHTML = "<h4>Dear K' " + name + " " + lname + "</h4>";
});