Hello every,
I am new to ajax. I have a webform on which i am performing ajax post call to a server side method but its not working
I am unable to figure it out
please help me getting out of it below is my code.
<link href="Styles/Bootstrap_3.4.1.min.css" rel="stylesheet" />
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">
<script src="Scripts/jQuery_3.5.1.js"></script>
<script src="Scripts/Bootstrap_3.4.1.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$('#iAdd').click(function () {
if ($('#txtEmp').val() != "" && $('#txtAmt').val() != "") {
var emp = $('#txtEmp_Code').val();
var amt = $('#txtAmt').val();
var rowCount = $('#gridManpower tr').length;
if (rowCount > 1 & rowCount != 2) {
rowCount = rowCount + 1;
} else if (rowCount == 1) {
rowCount = 1;
} else if (rowCount == 2) {
rowCount = 2;
}
$('#gridManpower').append("<tr><td>" + rowCount + "</td><td>" + emp + "</td><td>"
+ amt +
"</td><td><i class='fa fa-pencil' id='iEdit' style='color:purple; font-size:20px;'></i> | <i class='fa fa-trash' id='iDelt' style='color:purple; font-size:20px;'></i></td></tr>")
$.ajax({
type: 'POST',
url: 'WebForm1.aspx/test',
contentType: 'application/json',
data: '{test:' + emp + '}',
dataType: 'json',
success: function () {
alert('success');
},
error: function(){
alert(error);
}
})
} else {
alert('Please fill the required fields mark as read');
$('#txtEmp_Code').css("border-color", "red");
$('#txtAmt').css("border-color", "red");
}
})
$('#gridManpower').on('click', '#iEdit', function () {
var editId = $(this).attr('id');
$("#" + editId).hide();
var number = editId.replace("edit", "");
//$("#update" + number).show();
var currentTD = $(this).parents('tr').find('td');
$.each(currentTD, function () {
$(this).prop('contenteditable', true)
});
});
$('#gridManpower').on('click', '#iDelt', function () {
if (confirm('Are you sure you want to delete this') == true) {
$(this).closest('tr').remove();
}
});
})
</script>
In addition i would like to know whether its mandiatory to decorate this c# method with webmethod and static attributes?
[WebMethod]
public static void test(string test)
{
}