类型错误:无法读取的未定义的属性'jQuery的' [英] TypeError: Cannot read property 'jquery' of undefined

查看:1716
本文介绍了类型错误:无法读取的未定义的属性'jQuery的'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm getting the following error in Chrome console,

TypeError: Cannot read property 'jquery' of undefined

下面是我的javascript功能,

Here is my javascript function,

<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>

上面的错误方法是什么和为什么我有什么错?

What does above error means and where did I go wrong?

推荐答案

$ scope.formData.imageFile 似乎要评估未定义

$.param(undefined) //throws Cannot read property 'jquery' of undefined

做一个的console.log($ scope.formData) $ HTTP()呼叫。在 $ scope.formData 对象最有可能不包含镜像文件属性或镜像文件 / 未定义

Do a console.log($scope.formData) right before the $http() call. The $scope.formData object most likely does not contain an imageFile property, or imageFile is null/undefined.

注意 $。参数 需要一个普通的对象或数组作为第一个参数,提供了另一种类型的值(或没有值)下未定义的行为下降。

Note that $.param takes a plain object or array as the first argument, providing another type of value (or no value) falls under undefined behavior.

另外,如果我正确地读你的code,你想上传到 $ HTTP 的图像文件。它不会按照这种方式,你需要XHR2的 FORMDATA API 。请参见这个答案了一个简单的实现。

Also, if I'm reading your code correctly, you're trying to upload an image file through $http. It won't work that way, you need XHR2's FormData API. See this answer for a simple implementation.

角不支持 NG-模型&LT;输入类型=文件&GT; ,这是究其原因,前者的错误。

Angular does not support ng-model on <input type="file">, which is the reason for the former error.

这篇关于类型错误:无法读取的未定义的属性'jQuery的'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆