Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Passing several parameters - object and values
Message
Information générale
Forum:
Javascript
Catégorie:
Autre
Divers
Thread ID:
01609783
Message ID:
01609834
Vues:
56
This message has been marked as a message which has helped to the initial question of the thread.
>
>My question is how to pass multiple parameters to $http.get service where one parameter is an object and two other are string and boolean.
>

Create a top level object, and add the properties for each of the parameters.
$http.post(url, {
    parm1: { 
            name: 'rick',
            location: 'home',
            website: 'west-wind.com'     
        },
    parm2: id,
    parm3: key
});
JSON services generally can't receive 'multiple' parameters and can't receive complex objects via GET so you probably need to use POST to send the data. POST operations require that you pass a single object so that single object should be a wrapper around the 'parameters' you send. The server can then deconstruct that object and pull out the parameters.



+++ Rick ---

>>What are you trying to do? The code you're doing isn't doing anything - you're creating an empty promise that will never complete.
>>
>>All $http functions return a promise, so if you want to chain the callbacks and handle them in your controller just return the result from $http.get() etc.
>>
>>
>>function callService(parm1,parm2) {
>>   return $http.get('service/endpoint',{p1: parm1, p2: parm2})
>>              .success(function() { console.log('initial success"); })
>>              .error(function() { showError('failed"); });
>>}
>>
>>
>>Then the caller can do:
>>
>>
>>callService(parm1,parm2)
>>   .success(function() { alert('made it!' });
>>
>>
>>This is the way to delegate responsibility and have multiple intercept points for results returned from async operations. This is a common pattern if you use a service.
>>
>>+++ Rick ---
>>
>>
>>
>>>Hi everybody,
>>>
>>>I looked at this page
>>>
>>>https://docs.angularjs.org/api/ng/service/$http
>>>
>>>but it's still not clear to me.
>>>
>>>I have the following sample:
>>>
>>>
>>>var getAccounts = function(queryRequest) {
>>>            var deferred = $q.defer();
>>>            $http.get('/api/accounts', { params: queryRequest })
>>>                .success(function(data) {
>>>                    deferred.resolve(data);
>>>                })
>>>                .error(function(data, status, header, config) {
>>>                    deferred.reject(status);
>>>                });
>>>            return deferred.promise;
>>>        };
>>>
>>>        var getAccountInvoices = function (acctNameHash, showFinalized) {
>>>            var deferred = $q.defer();
>>>            $http.get('/api/accounts/getAccountInvoices/' + acctNameHash + '/' + showFinalized)
>>>                .success(function (data) {
>>>                    deferred.resolve(data);
>>>                })
>>>                .error(function (data, status, header, config) {
>>>                    deferred.reject(status);
>>>                });
>>>            return deferred.promise;
>>>        };
>>>
>>>Now, suppose I want to pass both to my getAccountInvoices - queryRequest object and two extra parameters (string and boolean). Should I just list them in the
>>>config object using this syntax:
>>>
>>>{ params: queryRequest, acctNameHash, showFinalized }
>>>
>>>?
>>>
>>>Thanks in advance.
+++ Rick ---

West Wind Technologies
Maui, Hawaii

west-wind.com/
West Wind Message Board
Rick's Web Log
Markdown Monster
---
Making waves on the Web

Where do you want to surf today?
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform