I am trying to program the following Curl command using Angular JS. I'm very new to AngularJS, so I may be missing something fundamental.To be specific, this is a mobile app, that is using the ionic framework (which uses Angular JS)
The curl command is this:
curl -X POST -d "username=xxxx&password=xxxx&action=login&view=console" http://myserver.com/zm/index.php?skin=xml
This works perfectly from command line.
In AngularJS, I have the following code:
angular.module('starter.controllers').controller('MonitorCtrl', function($ionicPlatform, $scope,$http)
{
console.log("***MAKING REQUEST");
//$http.defaults.headers.post["Content-Type"] = "application/x-www-form-urlencoded";
$http({
url:'http://myserver.com:9898/zm/index.php?skin=xml',
method:'post',
headers: {'Content-Type': 'application/x-www-form-urlencoded',
'Accept': '*/*',
},
transformRequest: function(obj) {
var str = [];
for(var p in obj)
str.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p]));
var foo= str.join("&");
console.log ("****RETURNING "+foo);
return foo;
},
data: {username:'admin',
password:'xxxx',
action:'login',
view:'console'}
})
.success (function()
{console.log("****YAY");
})
.error(function(data, status, headers, config)
{
console.log("***OOPS "+status + " H: "+data);
});
});
When I run this code, I see a POST request going to my server (I am sniffing using httpry) and a 200OK being returned from the server with the required payload, but my success handler is not being called. The error handler is called with a status of 0