TypeError:无法读取未定义的属性'jquery'

hel*_*rld 7 javascript jquery angularjs

我在Chrome控制台中收到以下错误,

TypeError: Cannot read property 'jquery' of undefined
Run Code Online (Sandbox Code Playgroud)

这是我的javascript函数,

<script type="text/javascript">
    var formApp = angular.module('formApp',[]);

    function formController($scope,$http){
        $scope.formData = {};

        $scope.processForm = function(){
            $http({
                method : 'POST',
                url : 'http://localhost:8080/ABCAPI/v1/image/front',
                data : $.param($scope.formData.imageFile),
                headers : {'Content-Type': "multipart/form-data" , 'Auth-Token' : "X"}
            }).success(function(data){
                console.log("");

                if (!data.success) {
                    // if not successful, bind errors to error variables

                } else {
                    // if successful, bind success message to message
                    $scope.message = data.message;
                }
            })
        };
    }

</script>
Run Code Online (Sandbox Code Playgroud)

上述错误意味着什么,我哪里出错了?

Fab*_*tté 12

$scope.formData.imageFile似乎评估为undefined.

$.param(undefined) //throws Cannot read property 'jquery' of undefined
Run Code Online (Sandbox Code Playgroud)

console.log($scope.formData)$http()通话前做好准备.该$scope.formData对象最有可能不包含imageFile属性,或者imageFilenull/ undefined.

请注意,$.param将普通对象或数组作为第一个参数,提供另一种类型的值(或没有值)属于未定义的行为.


此外,如果我正确地读取您的代码,您正试图通过上传图像文件$http.它不会那样工作,你需要XHR2的FormDataAPI.有关简单的实现,请参阅此答案.

Angular不支持ng-modelon <input type="file">,这是前一个错误的原因.

  • 此错误消息可能被视为jQuery错误. (3认同)