As I dive into AngularJS, one challenge I've encountered is integrating an AJAX call into my controller.js
file. I've already managed to get the login controller up and running with the same service as this one.
Now, my goal is to fetch data from the server using a different method in my service and then pass it to the HTML in a specific format. However, I'm unsure about the correct approach to achieve this. The code snippet below represents my initial attempt, drawing inspiration from a previous Chrome Packaged App project where manipulating display on HTML was simpler due to a single JavaScript file. This time around, I'm navigating through controllers, services, and the app structure.
.controller('VFCtrl', function($scope, $stateParams, $http, $ionicLoading, $state, $sce) {
$ionicLoading.show({
template: 'Loading...',
duration: 1000
});
$http.post('myService/mysite.aspx',{action: 'someMethodFromService', ParameterFromMethod: 'someValue'})
.success(function (response)
{
var htmldata='';
for(i=0;i<response.length;i++)
{
var htmlInfo = '<li><div class=\'col\'><a href="'+ response[i].Id +'"><img width=\'100%\' height=\'auto\' src="'+response[i].Image + '" class=\'profile-img\' /><h3>' +response[i].Name+'</h3><p>'+response[i].Title+'</p></a></div></li>';
htmldata+= htmlInfo;
}
$("#vflist").html(htmldata);
})
//I don't wanna change how to submit data in my html in the success part
//But if it MUST be change then I will.
.error(function(data, status, headers){
console.log(status);
});
})