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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T18:02:09+00:00 2026-05-27T18:02:09+00:00

Here’s my PHP code called during jQuery AJAX call: <?php include ‘../code_files/conn.php’; $conn =

  • 0

Here’s my PHP code called during jQuery AJAX call:

<?php
    include '../code_files/conn.php';
    $conn = new Connection();
    $query = 'SELECT Address_1, Address_2, City, State, OfficePhone1, OfficePhone2, Fax1, Fax2, Email_1, Email_2 
              FROM clients WHERE ID = ?';
    $conn->mysqli->stmt_init();
    $stmt = $conn->mysqli->prepare($query);
    $stmt->bind_param('s', $_POST['ID']);
    $stmt->execute();
    $result = $stmt->get_result();
    $row = $result->fetch_assoc();
    echo json_encode($row);
?>

And the client-side code is:

$.post(url, {ID:$('#ddlClients').val()},
        function(Result){
            // Result
        }
      );

The AJAX call is successfully completed. I get the value of Result as

"{"Address_1":"Divisional Office 1","Address_2":"The XYZ Road",.....and so on

What I want is to be able to use the values returned like Result.Address_1, Result.Address_2 and so on. But I can’t do it using the above code. I tried using $row = $result->fetch_object() and $row = $result->fetch_array(), but no use.

And I know that this can be done by this code on the server side:

$row = $result->fetch_assoc();
$retVal = array("Address_1"=>$row['Address_1'], "Address_2"=>$row['Address_2'].......);
echo json_encode($retVal);

or

$row = $result->fetch_object();
$retVal = array("Address_1"=>$row->Address_1, "Address_2"=>$row->Address_2.......);
echo json_encode($retVal);

Is there a way to send the $row directly to the client side JavaScript and ready to be used as JSON object, without manually creating an array first?

  • 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-27T18:02:10+00:00Added an answer on May 27, 2026 at 6:02 pm

    The response you are getting from your PHP script is in plain text. You can however parse that string into an object using $.parseJSON in your callback function:

    $.ajax({
        url      : url,//note that this is setting the `url` property to the value of the `url` variable
        data     : {ID:$('#ddlClients').val()},
        type     : 'post',
        success  : function(Result){
                var myObj = $.parseJSON(Result);
                //you can now access data like this:
                //myObj.Address_1
            }
        }
      );
    

    You can let jQuery do this for you by setting the dataType property for your AJAX call to json:

    $.ajax({
        url      : url//note that this is setting the `url` property to the value of the `url` variable
        data     : {ID:$('#ddlClients').val()},
        dataType : 'json',
        type     : 'post',
        success  : function(Result){
                //you can now access data like this:
                //Result.Address_1
            }
        }
      );
    

    The above examples expect that the response from the server to be in this format (from your question):

    "{"Address_1":"Divisional Office 1","Address_2":"The XYZ Road"}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is the code I'm using http://jsbin.com/evike5/edit When the jQuery UI dialog is fired
Here is my code: <?php $variable1 = 00001; $variable2 = (sprintf('%04d', $variable1 + 1));
Here's my code: // Not all headers are relevant to the code snippet. #include
Here is my code, which takes two version identifiers in the form 1, 5,
here is the site : http://www.notrepanorama.com at the bottom left, i use a jquery
Here's some of my production code (I had to force line breaks): task =
Here is a great article about GC may occur at unexpected point of code
Here is my javascript code for a cursor focus function to go to username
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
Here is my code...I have two dimensional matrices A,B. I want to develop the

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.