<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <script src="angular.min.js"></script> <script src="jquery.min.js"></script> </head> <body ng-app="myApp"> <div ng-controller="myController"> <input type="file" id="mainPic" onchange="angular.element(this).scope().menuPicChanged(this.id)"> </div> </body> <script> var app = angular.module('myApp', []); app.controller('myController', function ($scope,$http) { $scope.aa = "123456"; $scope.menuPicChanged = function (id) { console.log("menuPicChanged-----------------------------"); console.log('id == ' + id); var file = $("#" + id)[0].files[0]; console.log('file == ' + file); var fd = new FormData(); fd.append('file', file); fd.append('menuId', $scope.aa); $http({ method: 'POST', url: "http://119.23.313.212:80/common/CookerRecipeManngeController/mainPicSave", data: fd, headers: {'Content-Type': undefined}, transformRequest: angular.identity }).then(function successCallback(response) { alert("保存成功!") }, function errorCallback(response) { alert("url 请求数据错误!") }); }; }); </script> </html>
上传文件内容改变和上传文件
猜你喜欢
转载自huangyongxing310.iteye.com/blog/2373504
今日推荐
周排行