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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:00:43+00:00 2026-05-26T15:00:43+00:00

I have a problem with handling json variables in javascript. The problem appears when

  • 0

I have a problem with handling json variables in javascript.

The problem appears when I try to post data to a php class and then it should return 3 variables using JSON, but Firebug + FirePHP told me that the JSON variable returned correctly. Then when when I try to store each of them in different variables (3 returned json variables in 3 javascript variables) I just get the first parameter and the other two are NULL.

You can see in next javascript code:

function UpdateContact(ID)
{
    // get current Contact data
    var full_name,email,mobile;
    $.post("/Cards/index.php/Cont/GetContactInfo",{'id' : ID},
       function(data){
                full_name = data.full_name;
                email = data.email;
                mobile = data.mobile;
                   $( "#dialog2-form" ).html(
    '<p class="validateTips">All form fields are required.</p>'+
    '<form>'+
    '<fieldset>'+
        '<label for="name">Name</label>'+
        '<input type="text" name="Updatefull_name" id="Updatefull_name" class="text ui-widget-content ui-corner-all" value="'+full_name+'" /><br />'+
        '<label for="email">Email</label>'+
        '<input type="text" name="Updateemail" id="Updateemail" value="" class="text ui-widget-content ui-corner-all" value="'+data.email+'"/><br />'+
                '<label for="email">Mobile</label>'+
        '<input type="text" name="Updatemobile" id="Updatemobile" value="" class="text ui-widget-content ui-corner-all" value="'+data.mobile+'"/><br />'+
    '<input type="hidden" id="UpdateContactID" value="'+ID+'"></fieldset>'+
    '</form>'
);
   $( "#dialog2-form" ).dialog( "open" );
 }, "json");
}

Just the full_name variable is getting a value, but email and mobile variables do not get any value.

The PHP function is:

function GetContactInfo()
{
    $Contact = $this->Contacts->GetContacByID($this->input->post('id'));
    $data['full_name'] = $Contact->full_name;
    $data['email'] = $Contact->email;
    $data['mobile'] = $Contact->mobile;
    echo json_encode($data);
}

Note: I use CodeIgniter PHP Framework on my XAMPP localhost server

  • 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-26T15:00:43+00:00Added an answer on May 26, 2026 at 3:00 pm

    You need to check that the fields are present before using them:

    var field_to_read = some_default_value;
    if (typeof data['name_of_field'] !== 'undefined') {
       field_to_read = data['name_of_field'];
    }
    

    I suggest you use a construct similar to the above for reading your JSON data.

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

Sidebar

Related Questions

I'm having a problem handling JSON data within JavaScript, specifically in regards to using
I have problem when I try insert some data to Informix TEXT column via
I have a conceptual problem to do with PHP classes and error handling.. Below
I have a problem with slashes! I have some jQuery for handling generic dialogs
I have problem in some JavaScript that I am writing where the Switch statement
I have problem with return statment >.< I want to store all magazine names
I have a problem handling messages in a Thread. My run-method looks like this
I am using windows forms. I have a problem in handling mouse events. In
Hi I have a problem handling exceptions in wcf. I have a service like
I have a problem with jQuery click event handling. Here's my code: $j(#btn_renommer_groupe).click(function(){ document.forms['creation_edition_groupe'].reset();

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.