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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T05:27:37+00:00 2026-06-06T05:27:37+00:00

I am using jQuery’s $.post function to retrieve some data from a php file,

  • 0

I am using jQuery’s $.post function to retrieve some data from a php file, but the returned data does not seem to be showing? Here is what I have got.

Javascript Code:

$(document).ready(function(){
$("#import").click(function(){
        //This code works when uncommented, used for debugging.
        /*var x = "tester";
        $('input[name=title]').val(x);*/

        $.post("import.php", function(data){
            $('input[name=title]').empty().val(data.name); // John
            $('input[name=subtitle]').empty().val(data.time); //  2pm
            }, "json");
    });
});

PHP import.php Code:

<?php
    $my_array = array("name"=>"John","time"=>"2pm");
    echo json_encode($my_array); 
?>

Is there something silly I’ve missed out, or have I gone about this incorrectly. I’m fairly new to javascript/jquery.

  • 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-06T05:27:39+00:00Added an answer on June 6, 2026 at 5:27 am

    you have to use json.parse() and assign it to a variable to use it as an object.

    download json2.js from here

    json.parse has this documentation.

    a request type of JSON does not mean the ajax function returns the “data” value as an object. it is still a string and needs to be parsed with

    var myObject = JSON.parse(data);
    

    then you can use it like

    alert(myObject.name);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using jquery, I want to post data to from one of my pages to
Using Jquery AJAX to get a value from a PHP script. This line works
Using jQuery Ajax to fetch data from local server: it works well with IE8
Using jQuery to make an AJAX call to a PHP file results in the
using jquery's .post i send do my php code an object that with var_dump
Using jQuery and backbone.js, I would like to separate the JavaScript from the HTML
(using jquery) I have the following function $(function() { $('tr.parent') .css(cursor,pointer) .attr(title,Click to expand/collapse)
Using jQuery validation - validating on blur: $('input, select, radio, checkbox').blur(function(){ $(#createAccount).validate().element(this); }); If
Using jQuery, I make these changes in the DOM: $(document).ready(function() { $('.editable').click(function() { var
Using jquery I have a clicking tab mechanism that are nothing but anchor tags

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.