如果我使用 jquery ajax 但$http
Angular 不使用以下代码向服务器发送任何数据,则以下代码有效:
myapp.factory('startCampFactory',function($http,$q,$rootScope){
return {
startNewCampaign : function(){
var e = $("input#email");
var email = e.val();
var campname = $("input#campaignname").val();
var about = $("textarea#about").val();
var tamt = $("input#targetamount").val();
var edate = $("input#enddate").val();
var invitees = $("input#invitees").val();
var file_data = $("#file").prop("files")[0];
var form_data = new FormData();
form_data.append("file",file_data);
form_data.append("email",email);
form_data.append("campaignname",campname);
form_data.append("about",about);
form_data.append("targetamount",tamt);
form_data.append("enddate",edate);
form_data.append("invitees",invitees);
console.log(email+about+campname);
var deferred = $q.defer();
$http({
method:'POST',
url:'/startcampaign',
data:form_data,
headers:
{
'Content-Type' :'application/x-www-form-urlencoded'
}
}).success(function(data,status,headers,config) {
$rootScope.$apply( function() {
deferred.resolve();
});
}).error(function(){
$rootScope.$apply(function()
{
deferred.reject();
});
});
return deferred.promise;
}
});