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 8028343
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T00:06:35+00:00 2026-06-05T00:06:35+00:00

I’m attempting to build an application that uses JSON generated using PHP which is

  • 0

I’m attempting to build an application that uses JSON generated using PHP which is then managed using JavaScript.

At the moment it is not working as expected and I’m not sure why.

Snippet of code:

$(document).ready(function(){

      var projects = <?= $json; ?>;
      $(window).bind('hashchange', function(){

         var potential = window.location.hash.substring(1);

         $.each(projects, function(i,project){

            if (project.permalink == potential)
            {
               alert(project.title);
               $('#title').text(project.title);
               $('#agency').text(project.agency);
            }
            else
            {
               alert('potential: ' + potential + '. project.permalink: ' + project.permalink);
            }
        });
      });
   });

So after changing the URL’s hash section, I check to see if the permalink is listed in a block of JSON I have. (The permalink value). The alert says that project.permalink is undefined.

The PHP variable $json is created using PHP arrays and the json_encode() function.

The JSON is here:

   var projects = [{"hand-made-cards":{"id":"3","title":"Hand Made Cards","type":"","description":"","website_url":"http:\/\/northumberlhand-made.co.uk","agency":"-","permalink":"hand-made-cards","position":"1","added_by":"1","updated_by":"1","deleted_by":"0","published":"1","deleted":"0","datetime_added":"2012-06-03 16:42:14","datetime_updated":"2012-06-03 17:44:37","datetime_deleted":"0000-00-00 00:00:00","rel_id":"13"}},{"olive-design":{"id":"2","title":"Olive Design","type":"","description":"Olive Design website description. What happened here?","website_url":"http:\/\/olive-design.co.uk","agency":"Gardiner Richardson","permalink":"olive-design","position":"2","added_by":"1","updated_by":"1","deleted_by":"0","published":"1","deleted":"0","datetime_added":"2012-06-03 16:41:31","datetime_updated":"2012-06-03 17:43:50","datetime_deleted":"0000-00-00 00:00:00","rel_id":"14"}},{"riba-microsite":{"id":"1","title":"RIBA Microsite","type":"","description":"Some info abou the RIBA MS.","website_url":"http:\/\/ram.grtest.com","agency":"Gardiner Richardson","permalink":"riba-microsite","position":"3","added_by":"1","updated_by":"1","deleted_by":"0","published":"1","deleted":"0","datetime_added":"2012-06-03 16:40:55","datetime_updated":"2012-06-03 17:43:29","datetime_deleted":"0000-00-00 00:00:00","rel_id":"15"}}];

Updated JSON is here, as advised I have removed the additional object wrapping each object:

  var projects = [[{"id":"3","title":"Hand Made Cards","type":"","description":"","website_url":"http:\/\/northumberlhand-made.co.uk","agency":"-","permalink":"hand-made-cards","position":"1","added_by":"1","updated_by":"1","deleted_by":"0","published":"1","deleted":"0","datetime_added":"2012-06-03 16:42:14","datetime_updated":"2012-06-03 17:44:37","datetime_deleted":"0000-00-00 00:00:00","rel_id":"13"}],[{"id":"2","title":"Olive Design","type":"","description":"Olive Design website description. What happened here?","website_url":"http:\/\/olive-design.co.uk","agency":"Gardiner Richardson","permalink":"olive-design","position":"2","added_by":"1","updated_by":"1","deleted_by":"0","published":"1","deleted":"0","datetime_added":"2012-06-03 16:41:31","datetime_updated":"2012-06-03 17:43:50","datetime_deleted":"0000-00-00 00:00:00","rel_id":"14"}],[{"id":"1","title":"RIBA Microsite","type":"","description":"Some info abou the RIBA MS.","website_url":"http:\/\/ram.grtest.com","agency":"Gardiner Richardson","permalink":"riba-microsite","position":"3","added_by":"1","updated_by":"1","deleted_by":"0","published":"1","deleted":"0","datetime_added":"2012-06-03 16:40:55","datetime_updated":"2012-06-03 17:43:29","datetime_deleted":"0000-00-00 00:00:00","rel_id":"15"}]];
  • 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-05T00:06:37+00:00Added an answer on June 5, 2026 at 12:06 am

    You actually have an extra level in your JSON that does not make much sense: each project is enclosed in an additional object (re-indented the JSON for clarity):

    [
        {
            "hand-made-cards": {
                "id":"3",
                "title":"Hand Made Cards",
                "type":"",
                "description":"",
                "website_url":"http:\/\/northumberlhand-made.co.uk",
                "agency":"-",
                "permalink":"hand-made-cards",
                "position":"1",
                "added_by":"1",
                "updated_by":"1",
                "deleted_by":"0",
                "published":"1",
                "deleted":"0",
                "datetime_added":"2012-06-03 16:42:14",
                "datetime_updated":"2012-06-03 17:44:37",
                "datetime_deleted":"0000-00-00 00:00:00",
                "rel_id":"13"
            }
        },
    
        {
            "olive-design": {
                "id":"2",
                "title":"Olive Design",
                "type":"",
                "description":"Olive Design website description. What happened here?",
                "website_url":"http:\/\/olive-design.co.uk",
                "agency":"Gardiner Richardson",
                "permalink":"olive-design",
                "position":"2",
                "added_by":"1",
                "updated_by":"1",
                "deleted_by":"0",
                "published":"1",
                "deleted":"0",
                "datetime_added":"2012-06-03 16:41:31",
                "datetime_updated":"2012-06-03 17:43:50",
                "datetime_deleted":"0000-00-00 00:00:00",
                "rel_id":"14"
            }
        },
        ... (snip) ...
    

    My guess is you’ve got the JSON generated incorrectly in your PHP code, and need to change it to generate each project on the top-level in the JSON array instead of wrapped in an additional object.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I used javascript for loading a picture on my website depending on which small
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I'm trying to create an if statement in PHP that prevents a single post
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but

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.