im getting hexadecimal encoded value in the response. i have written code for hexa to ascii but i don't know how to pass the variable to the function and call the function to show decoded data in the plain text.getting error - names undefined
code
<script>
var app = angular.module('myApp', []);
app.controller('myCtrl', function ($scope, $http) {
$http.get('url', {
headers: { 'Authorization': 'Basic a2VybmVs==' }
})
.then(function (response) {
$scope.names = response.data;
});
});
</script>
<script>
function hex_to_ascii(str1) {
var hex = str1.toString();
var str = '';
for (var n = 0; n < hex.length; n += 2) {
str += String.fromCharCode(parseInt(hex.substr(n, 2), 16));
}
return str;
}
</script>
<h2>hex_to_ascii(names.hexadata)</h2>
Please take a mind you can change the model object name your wish.
<h2>{{name}}</h2>
And please merge your js code with angular and do the debug like as below
<script>
var app = angular.module('myApp', []);
app.controller('myCtrl', function ($scope, $http)
{
$scope.hex_to_ascii = function (str1) {
var hex = str1.toString();
var str = '';
for (var n = 0; n < hex.length; n += 2)
{
str += String.fromCharCode(parseInt(hex.substr(n, 2), 16));
}
return str;
}
$http.get('url',
{
headers: { 'Authorization': 'Basic a2VybmVs=='
}
}).then(function (response)
{
$scope.names = response.data;
$scope.name = hex_to_ascii($scope.names.hexadata);
});
});
</script>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.