Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to change post['Content-Type'] in angularjs

Tags:

angularjs

i want to change post['Content-Type'] in angularjs so i use

  app.config(function($locationProvider,$httpProvider) {
$locationProvider.html5Mode(false);
$httpProvider.defaults.useXDomain = true;
delete $httpProvider.defaults.headers.common['X-Requested-With'];
$httpProvider.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded;        charset=UTF-8';
 });

and the event is

     $http.post("http://172.22.71.107:8888/ajax/login",{admin_name:user.u_name,admin_password:user.cert})
        .success(function(arg_result){

            console.log(arg_result);


        });
};

however the rusult is

Parametersapplication/x-www-form-urlencoded
{"admin_name":"dd"} 

what i want is

Parametersapplication/x-www-form-urlencoded
 admin_name dd

so what i should do?

like image 667
XzAngular Avatar asked Jul 12 '13 07:07

XzAngular


People also ask

How do you modify the $HTTP request default Behaviour?

To add or overwrite these defaults, simply add or remove a property from these configuration objects. To add headers for an HTTP method other than POST or PUT, simply add a new object with the lowercased HTTP method name as the key, e.g. $httpProvider. defaults.

What is HTTP post in AngularJS?

AngularJS Http Post ($http. POST() services are used to send the data to a specific URL and expects the resource at that URL to handle the request that means we can say that POST method is used to Insert new data based on given URL and it is one of the shortcut method in $http service.

What is $location in AngularJS?

Overview. The $location service parses the URL in the browser address bar (based on the window. location) and makes the URL available to your application. Changes to the URL in the address bar are reflected into $location service and changes to $location are reflected into the browser address bar.

What is $scope in angular?

$rootScope is a parent object of all “$scope” angular objects created in a webpage. $scope is a child object that is used to bind the HTML(view) & Javascript(Controller) in a webpage. It is created with the ng-app directive. It is created with the ng-controller directive.


1 Answers

Try like:

var serializedData = $.param({admin_name:user.u_name,admin_password:user.cert});

$http({
    method: 'POST',
    url: 'http://172.22.71.107:8888/ajax/login',
    data: serializedData,
    headers: {
        'Content-Type': 'application/x-www-form-urlencoded'
    }}).then(function(result) {
           console.log(result);
       }, function(error) {
           console.log(error);
       });
like image 178
holographic-principle Avatar answered Sep 23 '22 11:09

holographic-principle