Created
October 18, 2013 08:46
-
-
Save swampie/7038546 to your computer and use it in GitHub Desktop.
angular upload with jquery-form
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$scope.errors = {} | |
if(!$scope.image){ | |
console.log('error'); | |
$scope.errors["image"] = "L'immagine non puó essere vuota"; | |
} | |
if(!$scope.assetname || $scope.assetname == ''){ | |
$scope.errors["name"] = "L'immagine non puó essere vuota"; | |
} | |
if(isEmpty($scope.errors)){ | |
if(navigator.appName.indexOf("Internet Explorer")!=-1){ | |
var badBrowser=( | |
navigator.appVersion.indexOf("MSIE 1")==-1 | |
); | |
if(!badBrowser){ | |
var fd = new FormData(); | |
fd.append("file", $scope.image); | |
fd.append("name", $scope.assetName); | |
$http.post(BBHostNoPort+'/admin/asset',fd,{ | |
headers: { | |
'Content-Type': undefined, | |
'X-BB-SESSION':authService.token() | |
}, | |
transformRequest: angular.identity | |
}) | |
}else{ | |
var options = { | |
url: BBHostNoPort+"/asset/admin", | |
type: "post", | |
beforeSend:function(xhr){ | |
xhr.setRequestHeader("X-BB-SESSION",authService.token()) | |
}, | |
dataType: "json", | |
success: function(){ | |
console.log("done") | |
}, //success | |
error: function(data) { | |
console.log("error",data) | |
} | |
}; | |
$('#assetForm').ajaxSubmit(options); | |
} | |
}else{ | |
console.log("There are errors"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment