Would appreciate some light shed on the following issue. I need to do an HTTP Post with XML data in my AngularJS client. I was able to achieve that using $.ajax POST:
$.ajax({
url: url,
type: 'POST',
data: data,
dataType: 'text',
success: function (result) {
alert(result);
},
error: function (jqXHR, tranStatus, errorThrown) {
alert('Status: ' + jqXHR.status + ' ' + jqXHR.statusText + '. ' +
'Response: ' + jqXHR.responseText);
}
});
However, I wasn't able to figure out how to do it using $http or $resource:
$http({
url: url,
method: 'POST',
data: data,
headers: {"Content-Type": "application/xml"}
}).success(function (result) {
alert(result);
}).error(function (error) {
alert(error);
});
Where url and data are something like that:
url: 'http://192.168.1.3:8900'
data: "<PARENT><CHILD_1>1</CHILD_1><CHILD_2>Two</CHILD_2></PARENT>"
I have reviewed this from jquery $.ajax to angular $http
and this Angularjs $http VS jquery $.ajax
and didn't find any clarification to my dilemma. CORS is not an issue as it's enabled in my browser (Chrome). With $http I simply get "angular.js:9814 OPTIONS http://192.168.1.3:8900/ net::ERR_EMPTY_RESPONSE". And it errors out right away. Could it be something to do with the port? Host url looks good in dev tools...
Any tip will be much appreciated!
EDIT: I've tried the content-type for $http before with no difference. I reviewed POST-ing XML in AngularJS and the question is different from mine. I have plenty of other $resource as well as older $http calls throughout my app as well as CORS calls to cross-domain WebAPI and have a decent experience with angularjs. However, I have never posted XML - always json.