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

  • Home
  • SEARCH
  • 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 6373127
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T01:19:31+00:00 2026-05-25T01:19:31+00:00

i have this code: <script> $(document).ready(function() { refresh(); }); function refresh() { $.get(‘getMessageDetails.php’, function

  • 0

i have this code:

<script>
    $(document).ready(function()
    {
        refresh();
    });

    function refresh()
    {      
        $.get('getMessageDetails.php', function (json) {
            alert(json);  //as a test for now
        });
    }
</script>

then i have my getMessageDetails.php:

<?php
header('Content-Type: application/json; charset=utf-8');
include('header_application.php');
$lastNewMessageCnt = $obj_clean->getUnopenedMessagesCount($_SESSION['user_id']) + 1;
$last_unopened_message_row = $obj_clean->getLastUnopenedMessage($_SESSION['user_id'],$lastNewMessageCnt); 

echo json_encode($last_unopened_message_row);

?>

and my html:

echo "<tr>";
echo '<td><a id = "message_id" class="red_link" href="'.ADDRESS.'view_message.php?id='.$r['id'].'"><span id = "subject">'.$r['subject'].'</span></a></td>';
echo '<td id = "unique_code1">'.$uniqueCode1.'<span id = "unique_code2" class="pink_text">'.$uniqueCode2.'</span><span id = "unique_code3">'.$uniqueCode3.'</span></td>';
echo "</tr>";

how come when i alert(json) i get the values im supposed to get which is the last message:

[{"subject":"Freechat ha ha","id":"15","created_at":"2011-08-29 11:16:45","unique_code":"LUCINEM000RC","opened_once":"0"}]

BUT as soon as i code this:

alert($("#subject").html(json.subject));  
alert($("#message_id").html(json.id));
alert($("#unique_code1").html(json.unique_code));

i get the first message’s details??? which is not what i want
where am i going wrong please??
thank you

  • 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-05-25T01:19:31+00:00Added an answer on May 25, 2026 at 1:19 am

    in JSON

    • object are denoted by {}
    • array are denoted by []

    so to access the requred data, you need to do so..

    alert(json[0].subject);
    alert('<br>'+json[0].id);
    alert('<br>'+json[0].created_at);
    alert('<br>'+json[0].unique_code);
    alert('<br>'+json[0].opened_once);
    

    DEMO

    UPDATE

    actually there is problem in ur jquery function

    either use jQuery.getJSON()

    or if you are using jQuery.get then write "json" as an third argument like this

    function refresh()
        {      
            $.get('getMessageDetails.php', function (json) {               
            },"json"); // <---here
        }
    

    NOTE: why don’t you install firebug, that will tell your error runtime

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

Sidebar

Related Questions

i have this code: <script> $(document).ready(function() { refresh(); }); function refresh() { $.get('getMessageDetails.php', function
i have this code: <script> $(document).ready(function() { refresh(); }); function refresh() { $.post('getMessageDetails.php', function
I have this code: <script> $(document).ready(function(){ $('form').validate({ //rules: { 'input_name': { email: true} },
I have this code : <script type=text/javascript> $(document).ready(function() { $('.classSelect').change(function() { // somethings });
I have this code : <script type=text/javascript> $(document).ready(function() { $('.trackInputHours').change(function() { $(this).closest('.trackOn').nextAll('.trackOn').find('.trackInputHours').val($(this).val()); }); });
I have the following code that works: <script type=text/javascript> $(document).ready(function() { // Initialise the
Right now my code looks like this: <script type=text/javascript> $(document).ready(function() { $.ajaxSetup({ cache: false
I have this code below: <?php function wp_copickpage() { color_option_update(); ?> <form method=POST action=>
I have this java code: <script src=http://www.google.com/jsapi></script> <script type=text/javascript> google.load(jquery, 1.2.6); $(a#more).click(function() { $(#info_box).show(blind,
I have a greasemonkey user script with this single line of code... window.close(); 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.