简体   繁体   中英

JavaScript Error: “ReferenceError: array is not defined”

I want to make a JavaScript array and pass it to another page in php via post request I get an error in 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 cakePHP view.

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

var data = new Array();

However you may always use a short version:

var data = [];

You need to declare array above where it is use.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM