1. 程式人生 > >$http的post請求

$http的post請求

在開發一個angular專案時,發現$http的post請求有2種不同的形式。分為包括檔案的表單與純文字框的表單。

1.有檔案上傳的表單:
 $http.post(saveUrl, formdata, { 
     headers: {'Content-Type':undefined}, 
     transformRequest: angular.identity 
     }).success(function(responseData) {   
	   console.log(responseData)
 };


2.純文字框的表單:
var postCfg = {
            headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
            transformRequest: function (data) {
                return $.param(data);
            }
        };
        $http.post(FormUrl,{num:num,size:size},postCfg).success(function(data){
        console.log(data);
        });