JavaScript 错误:“ReferenceError:未定义数组”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14293897/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-24 16:17:23  来源:igfitidea点击:

JavaScript Error: "ReferenceError: array is not defined"

javascriptjqueryarrayscakephp

提问by UserNew

I want to make a JavaScript arrayand pass it to another page in php via post request I get an error in firebug:

我想制作一个 JavaScriptarray并通过 post 请求将它传递到 php 中的另一个页面我在 firebug 中收到一个错误:

ReferenceError: array is not defined

参考错误:未定义数组

Here's the code:

这是代码:

$(document).ready(function(){
    var data = new array();               // this line throws the error
    // Handle Submiting form data
    $("#btnSumbit").click(function (){

        $('#tblCriteria input[type=text]').each(
            function(){
                data[this.id] = this.value;
            }
        );  

This code inside cakePHPview.

这段代码里面cakePHP视图。

回答by VisioN

JavaScript is case sensitive, so to create a new array write Arraywith a capital letter:

JavaScript 区分大小写,因此要创建一个新数组Array,请使用大写字母写入:

var data = new Array();

However you may always use a short version:

但是,您可能总是使用简短版本:

var data = [];

回答by Connectify_user

You need to declare array above where it is use.

您需要在使用它的地方上方声明数组。

var arrayName = [ ]; //  1
var arrayName = new array(); //  2