Faizul Mustafiz Faizul Mustafiz - 1 month ago 7
AngularJS Question

How to solve this using Angular where it works perfectly in JQuery?

Hi I am New to ANgularJs.
I Have a WebService.asmx which expects two parameter and returns a bool variable in MachineAssigned variable now in jQuery It works perfectly but Not in Angulajs
"I have A jQuery Code which works perfectly"

$('#saveButton').click(function () {
var machineNo = $('#machineNumberTextBox').val();
var empCode = $('#employeeCodeTextBox').val();
var empName = $('#empNameTextbox').val();
if (machineNo.length > 0 && empCode.length > 0) {
$.ajax({
url: "WebService.asmx/IsMachineAssigned",
method: 'post',
data: 'machineNumber=' + machineNo + '&employeeCode=' + empCode,
dataType: 'json',
success: function (data) {
if (data.MachineAssigned) {
$('#divResult').text("Machine " + machineNo + " is already assigned to this " + empCode + " : " + empName);
$('#divResult').css('color', 'red');
} else {
$('#divResult').text("Machine " + machineNo + " is available for this " + empCode + " : " + empName);
$('#divResult').css('color', 'green');
}
}
})
}
})


"But in AngularJS Same logic is not Working"

var machineNo = $scope.machine.MachineNumber;
var empCode = $scope.operator.EmployeeCode;
//var params = { machineNumber: machineNo, employeeCode: empCode }
$http({
method: 'post',
url: "WebService.asmx/IsMachineAssigned",
//date: 'machineNumber=' + JSON.parse(machineNo) + '&employeeCode=' + JSON.parse(empCode),
contentType: "application/json; charset=utf-8",
data: 'machineNumber=' + machineNo + '&employeeCode=' + empCode,
datatype: "json"
}).success(function (resopnse) {
if (data.MachineAssigned) {
alert("This Machine already assigned");
} else {
alert("This Machine is available");
}
})


I Tried every Thing Please Help Me

Answer

Try this:

var machineNo = $scope.machine.MachineNumber;
var empCode = $scope.operator.EmployeeCode;
var params = $.param({ 'machineNumber': machineNo, 'employeeCode': empCode }); // here 
Comments