0

I am learning angularJS and I want to know how can I send multiple data variables through Angular AJAX like I could do with Jquery?

This is how I did it with Jquery:

$.post("eventCreate.php",
                        {
                            daySelect: daySelect,
                            startTime: startTime,
                            endTime: endTime,
                            eventName: eventName,
                            loginName: "<?php echo $user; ?>",
                            sliderName: sliderName
                        },
                        function(result)
                        {
                          ;
                        });

So how do I do this with Angularjs? Is it possible?

2

2 Answers 2

1

You can use $http and $resource service of angular.I mostly use $http.You can send multiple variable in angular js ajax call in data or params atttibute of $http as given below

$http({
    url: user.details_path, 
    method: "GET",
    params: {user_id: user.id,user_name:user.name}
 });

 $http({
        url: user.details_path, 
        method: "GET",
        data: userObject
     });
Sign up to request clarification or add additional context in comments.

Comments

-2

In AngularJs we create Controllers and do our things in it. AngularJs support POST and GET method as well. In this code i am giving you a demo for POST method. Change variable name according to you and you can increase and decrease them as well.

Use $_POST for server side to get the value of these.

$scope.YourControllerName = function () {
    var req = {
            method: 'POST',
            url: 'YourURL',
            headers: {'Content-Type': 'application/x-www-form-urlencoded'},
            data: {
                userId: userId,
                userName: userName, // Or anything you want to send
                action: "addUser"  //Suppose you are adding a user
               },
            }

            $http(req).then(function(response){
                //This will called on success do something with this response
            }, function(response){
                //This will called on failure do something with this response
            });
        };

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.