最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

jquery - JavaScript Error: "ReferenceError: array is not defined" - Stack Overflow

programmeradmin3浏览0评论

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.

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.

Share Improve this question edited Jan 14, 2013 at 14:48 Eric Leschinski 154k96 gold badges422 silver badges337 bronze badges asked Jan 12, 2013 at 13:45 UserNewUserNew 831 gold badge1 silver badge4 bronze badges 2
  • Try to move var data = new array();in the top on script or rename data to other name. – Norbert Pisz Commented Jan 12, 2013 at 13:47
  • MDN has a good JavaScript tutorial: developer.mozilla.org/en-US/docs/JavaScript/Guide. Also good: eloquentjavascript.net. – Felix Kling Commented Jan 12, 2013 at 13:58
Add a comment  | 

2 Answers 2

Reset to default 21

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 before it was used checking case sensitive name

 var arrayName = []; //  1
          or
 var arrayName = new Array(); //  2 
发布评论

评论列表(0)

  1. 暂无评论