i am start to learn about angular js. I have a javascript function which is post function, now i want to convert it to angular js.
Here is my old javascript code:
<script>
function submitFunction() {
var ip_range = "";
var user_name = "wind";
$.post("software.aspx", {"action": "getchartdata","username": user_name},
function(data, status) {
if (status === "success") {
if (data) {
console.log(JSON.stringify(data));
dataParse(data);
} else {
alert("ALERT!");
}
alert(start_date)
}
alert(start_date)
});
}
</script>
I can get the return result from this old javascript, it return me the json result. Below is my new angular js function which couldnt works. I not sure whether i need to change the backend code.
<script>
var app = angular.module('myApp', []);
app.controller('FormCtrl', function ($scope, $http) {
console.log("Preparing..")
$scope.submitForm = function () {
console.log("posting data....");
var username = $scope.form;
$http({
method: 'POST',
url: 'Software.aspx',
data: {username: username},
}).then(function successCallback(response) {
// this callback will be called asynchronously
// when the response is available
console.log("Success")
console.log(response)
}, function errorCallback(response) {
// called asynchronously if an error occurs
// or server returns response with an error status.
console.log("fail")
});
};
});
</script>
I wish someone to tell me what i less to convert into angular js. Thanks.
url: 'Software.aspx',angularjs.