I want to use web service using JQuery In Hybrid app. For That i have created html page using AngularJS.
<form id="form1" ng-controller="EmpCtrl" ng-submit="save()">
<div style="font-family: Verdana; font-size: 12px; margin-left: 450px;">
<table>
<tr>
<td style="text-align: right;">Id :
</td>
<td>
<input type="text" id="txtEmpID" ng-model="EmpID" />
</td>
</tr>
<tr>
<td style="text-align: right;">First Name :
</td>
<td>
<input type="text" id="txtEmpFirstName" ng-model="EmpFirstName" />
</td>
</tr>
<tr>
<td style="text-align: right;">Last Name :
</td>
<td>
<input type="text" id="txtEmpLastName" ng-model="EmpLastName" />
</td>
</tr>
<tr>
<td style="text-align: right;">Address :
</td>
<td>
<textarea id="txtEmpAddress" cols="20" rows="2" ng-model="EmpAddress"></textarea>
</td>
</tr>
<tr>
<td style="text-align: right;">City :
</td>
<td>
<input type="text" id="txtCity" ng-model="EmpCity" />
</td>
</tr>
<tr>
<td style="text-align: right;">Pin Code :
</td>
<td>
<input type="text" id="txtPinCode" ng-model="EmpPincode" />
</td>
</tr>
<tr>
<td style="text-align: right;">State :
</td>
<td>
<input type="text" id="txtState" ng-model="EmpState" />
</td>
</tr>
<tr>
<td style="text-align: right;">Country :
</td>
<td>
<input type="text" id="txtCountry" ng-model="EmpCountry" />
</td>
</tr>
<tr>
<td colspan="2" style="text-align: center;">
<input type="submit" id="btnSubmit" value="Submit" />
</td>
</tr>
</table>
</div>
<div>
<input type="button" id="btnFetch" value="Fetch" ng-click="getEmployee()"/>
</div>
<div id="divTesting">
</div>
And create JQuery. In which i defined ng-app and ng-controller:
function EmpCtrl($scope)
{
$scope.getEmployee = function () {
$.ajax({
type: "POST",
url: 'http://www.athithi.com/EmpService.asmx/GetEmployeeDetails',
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
var TableContent =
"<table border='0'>" +
"<tr>" +
"<td>ID</td>" +
"<td>First Name</td>" +
"<td>Last Name</td>" +
"<td>Address</td>" +
"<td>City</td>" +
"<td>PinCode</td>" +
"<td>State</td>" +
"<td>Country</td>" +
"</tr>";
for (var i = 0; i < data.d.length; i++) {
TableContent += "<tr>" +
"<td>" + data.d[i].ID + "</td>" +
"<td>" + data.d[i].FirstName + "</td>" +
"<td>" + data.d[i].LastName + "</td>" +
"<td>" + data.d[i].Address + "</td>" +
"<td>" + data.d[i].City + "</td>" +
"<td>" + data.d[i].Pincode + "</td>" +
"<td>" + data.d[i].State + "</td>" +
"<td>" + data.d[i].Country + "</td>" +
"</tr>";
TableContent += "</table>";
$("#divTesting").html(TableContent);
}
},
error: function (msg) {
alert("Error");
}
});
};
$scope.save = function () {
$.ajax({
type: "POST",
url: "EmpService.asmx/InsertEmployee",
data: "{'empID':'" + $scope.EmpID + "','firstName':'" + $scope.EmpFirstName + "','lastName':'" + $scope.EmpLastName + "','address':'" + $scope.EmpAddress + "','city':'" + $scope.EmpCity + "','pincode':'" + $scope.EmpPincode + "','state':'" + $scope.EmpState + "','country':'" + $scope.country + "'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (msg) {
alert(msg.d);
},
error: function (msg) {
alert("err hello");
}
});
};
}
It's work fine when i use url: EmpService.asmx/InsertEmployee
and url: EmpService.asmx/GetEmployeeDetails
but when i use Hosted IIS web service (http://www.athithi.com/EmpService.asmx/InsertEmployee('')
and http://www.athithi.com/EmpService.asmx/GetEmployeeDetails
) it does not work. properly.