$Http.Get(...).Success Is Not a Function

$http.get(...).success is not a function

The .success syntax was correct up to Angular v1.4.3.

For versions up to Angular v.1.6, you have to use then method. The then() method takes two arguments: a success and an error callback which will be called with a response object.

Using the then() method, attach a callback function to the returned promise.

Something like this:

app.controller('MainCtrl', function ($scope, $http){
$http({
method: 'GET',
url: 'api/url-api'
}).then(function (response){

},function (error){

});
}

See reference here.

Shortcut methods are also available.

$http.get('api/url-api').then(successCallback, errorCallback);

function successCallback(response){
//success code
}
function errorCallback(error){
//error code
}

The data you get from the response is expected to be in JSON format.
JSON is a great way of transporting data, and it is easy to use within AngularJS

The major difference between the 2 is that .then() call returns a promise (resolved with a value returned from a callback) while .success() is more traditional way of registering callbacks and doesn't return a promise.

Error with $http.get in angularJS -- Success not a Function

The .success and .error methods are deprecated and have been removed from AngularJS 1.6. Use the standard .then method instead.

$http.get('https://api.github.com/users')
.then(function (response) {

var data = response.data;
var status = response.status;
var statusText = response.statusText;
var headers = response.headers;
var config = response.config;

$scope.user = data;
console.log(data);
});

Deprecation Notice


The $http legacy promise methods .success and .error have been deprecated and will be removed in v1.6.0. Use the standard .then method instead.

— AngularJS (v1.5) $http Service API Reference -- Deprecation Notice.

Also see SO: Why are angular $http success/error methods deprecated?.

$http.get(...).success is not a function

Success is deprecated. Use then.

$http.get().then(function success(result){

}, function error(err) {

})

Angular $http(...).success is not a function help rewriting the function

For angular 1.6.4 use .then and .catch to deal with the response and the error respectfully:

(note you can save some lines of code by using $http.post)

$scope.init = function(){
$http.post('yourURL', $scope.yourData).
then(function(results) {
if(results.data.success ){
$scope.post.users = results.data;
}else{
$scope.messageFailure(results.data.message);
}
}).
catch(function(results) {
//$scope.messageFailure(results.data.message);
});
};

AngularJS error .success is not a function

See 'Deprecation Notice' from $http service documentation:

The $http legacy promise methods success and error have been
deprecated. Use the standard then method instead.

You can learn more about these methods in the documentation about $q.

AngularJS : TypeError: $http(...).success is not a function on asp.net WebMethod

It should be like this

 $http({
method: "POST",
url: "Index.aspx/GetData",
dataType: 'json',
data: {},
headers: { "Content-Type": "application/json" }
}).then(function(result) {
//Success
}, function(error) {
//Error
});

Virtual addresses size computing

Your answers are exactly right.

With a 32-bit address bus, you can access a virtual space of 2^32 unique addresses.

Each 4K page uses 2^12 (physical) addresses, so you can fit (2^32) / (2^12) = 2^20 pages into the space.

Good luck with your exam!


Edit to address questions in the comments:

How do you know you cannot access more than 2^32 addresses?

A 32-bit address bus means there are 32 wires connected to the address pins on the RAM--each wire is represented by one of the bits. Each wire is held at either a high or low voltage, depending on whether the corresponding bit is 1 or 0, and each particular combination of ones and zeroes, represented by a 32-bit value such as 0xFFFF0000, selects a corresponding memory location. With 32 wires, there are 2^32 unique combinations of voltages on the address pins, which means you can access 2^32 locations.

So what about the 4K page size?

If the system has a page size of 4K, it means the RAM chips in each page have 12 address bits (because 2^12 = 4K). If your hypothetical system has 128K of RAM, you'd need 128K/4K = 32 pages, or sets of RAM chips. So you can use 12 bits to select the physical address on each chip by routing the same 12 wires to the 12 address pins on every RAM chip. Then use 5 more wires to select which one of the 32 pages contains the address you want. We've used 12 + 5 = 17 address bits to access 2^17 = 128K of RAM.

Let's take the final step and imagine that the 128K of RAM resides on a memory card. But with a 32-bit address bus, you still have 32-17 = 15 address bits left! You can use those bits to select one of 2^15 = 32768 memory cards, giving you a total virtual address space of 2^32 = 4G of RAM.

Is this useful beyond RAM and memory cards?

It's common practice to divide a large set of bits, like those in the address, into smaller sub-groups to make them more manageable. Sometimes they're divided for physical reasons, such as address pins and memory cards; other times it's for logical reasons, such as IP addresses and subnets. The beauty is that the implementation details are irrelevant to the end user. If you access memory at address 0x48C7D3AB, you don't care which RAM chip it's in, or how the memory is arranged, as long as a memory cell is present. And when you browse to 67.199.15.132, you don't care if the computer is on a class C subnet as long as it accepts your upvotes. :-)



Related Topics



Leave a reply



Submit