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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T05:59:56+00:00 2026-05-19T05:59:56+00:00

I am trying to use a $.post() in the following way: $.post(file.php, { file_id:

  • 0

I am trying to use a $.post() in the following way:

$.post("file.php", { file_id: $(this).val()}, function(data){...}
The file.php then does a database query and returns an array with a title, description and image reference.

What I want to do then is be able to update the .val() for form fields for each. I understand how to do this on a single variable, it would just be the following:

$.post("file.php", { file_id: $(this).val()}, function(data){ 
   $('#title').val(data);
}

But, how do I get the data returned to be recognizable in jquery as either separate variables or as an array?

Thanks in advance

  • 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-19T05:59:58+00:00Added an answer on May 19, 2026 at 5:59 am

    See the docs for $.post. The fourth parameter is the dataType. You can set this to JSON for your return data to be parsed into a JavaScript object or array.

    $.post(
       "file.php", 
       { file_id: $(this).val() }, 
       function(data){ $('#title').val(data.title); $('#para').val(data.paragraph); },
       'json');
    

    In your file.php file, you can do something like

    <?php
    $return_data=array('title'=>'Fishes Go To Market','paragraph'=>'Lots of stuff');
    
    header('Content-Type: application/json');
    echo json_encode($return_data);
    exit();
    

    Be sure to include the header() so jQuery knows your data is supposed to be JSON, and to use json_encode so it is formatted properly.

    See the json_encode docs for more info on that, and the docs on header. Remeber you can’t have any other output come before your header() and printing the json_encoded data, or the header as well as the JSON will be invalid.

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

Sidebar

Related Questions

I'm trying to use jQuery.post() function to retrieve some data. But i get no
I've been trying to use SQLite with the PDO wrapper in PHP with mixed
I have an HTML form POSTing to the following index.php: <?php require_once(/home/full/path/to/included/file.php); ?> And
I'm trying to perform the following post build step in a VS2008 project: sn.exe
I'm trying to use XSLT text output to generate a file (in a file
I am trying to come up with a function that does a good job
I'm trying to use decorators in order to manage the way users may or
I am trying to reproduce the following but my using rows from the database
I am trying to use PHP to build HTML that I will later display.
Trying to use an excpetion class which could provide location reference for XML parsing,

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.