Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8160093
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T18:08:08+00:00 2026-06-06T18:08:08+00:00

Currently working for the first time with JSON and with little experience of jQuery.

  • 0

Currently working for the first time with JSON and with little experience of jQuery.
I have this function that gets triggered on “success” of $.ajax request:

function(data) {

    $.each(data.notifications, function(notifications) {
        alert('New Notification!');
    });

}

However I get an error in the firebug console stating “object is undefined” “length = object.length”.

The JSON response is:

["notifications",[["test would like to connect with you",{"Accept":"\/events\/index.php\/user\/connection?userId=20625101&action=accept","Decline":"\/events\/index.php\/user\/connection?userId=20625101&action=decline"}]]]

I guess it has something to do with the number of []s but the JSON was encoded by PHP using json_encode()

Any help would be appreciated!

Thanks 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T18:08:10+00:00Added an answer on June 6, 2026 at 6:08 pm

    What you have is a JSON Array. I’m guessing you were looking for something like this:

    {
        "notifications": [
            ["test would like to connect with you",
            {
                "Accept": "\/events\/index.php\/user\/connection?userId=20625101&action=accept",
                "Decline": "\/events\/index.php\/user\/connection?userId=20625101&action=decline"
            }]
        ]
    }
    

    Although I think a better structure would be:

    {
        "notifications": [
            {
                "message": "test would like to connect with you",
                "Accept": "\/events\/index.php\/user\/connection?userId=20625101&action=accept",
                "Decline": "\/events\/index.php\/user\/connection?userId=20625101&action=decline"
            }
        ]
    }
    

    This way notification becomes a property of the object, which means you can access it via data.notifications. Otherwise you’d have to access the notifications via data[1] (data[0] would contain the string “notifications” which essentially becomes meaningless).

    The following example should give you an idea as far as setting up your data in PHP:

    <?php
      $array = array(
          "notifications" => array(
              array(
                  "message" => "Test would like to connect with you",
                  "Accept" => "/events/index.php/user/connection?userId=20625101&action=accept",
                  "Decline" => "/events/index.php/user/connection?userId=20625101&action=decline"
              )
          )
      );
    
      echo json_encode($array);
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently working on an ASP.NET MVC2 project. This is the first time
I have just installed a custom WordPress theme (this is my first time working
I have just started to create a stored function this is my first time
Currently I'm working on an assignment and using C++ for the first time. I'm
I am currently working directly with Cocoa for the first time to built a
I'm using the jQuery DatePicker control for the first time. I've got it working
I am working on a basic page with jquery-mobile. I currently have 2 pages
I'm currently working on a command line tool and since this is my first
I'm a beginner in WPF and currently working on my first app. For this
I am currently working on a project. In this project I have set of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.