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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T19:20:18+00:00 2026-05-25T19:20:18+00:00

I want in output this PHP code echo name , star_type , service by

  • 0

I want in output this PHP code echo name, star_type, service by jquery.each(), but i have error. how is fix it?

error:

An error has occured:
[object Object]
parsererror
SyntaxError: JSON.parse: unexpected non-whitespace character after
JSON data

I have this PHP code:

//$hotel_id = $this->input->post('hotel_id');
$hotel_id = array('1','2','3');
//print_r($hotel_id);
foreach ($hotel_id as $val) {
    $query_r = $this->db->query("SELECT * FROM hotel_submits WHERE id LIKE '$val' ORDER BY id desc");
    $data    = array();
    foreach ($query_r->result() as $row) {
        $data_s  = json_decode($row->service, true);
        $data_rp = json_decode($row->address, true);
        $data[]  = array(
            'name' => $row->name,
            'star_type' => $row->star . '-' . $row->type,
            'site' => $row->site,
            'service' => $data_s,
            'address' => $row->address
        );
    }
    echo json_encode($data);
}

This is output above PHP code:

[{
    "name": "how",
    "star_type": "5-hotel",
    "site": "www.sasaas.assa",
    "service": ["shalo", "jikh", "gjhd", "saed", "saff", "fcds"]"address": "chara bia paeen"
}][{
    "name": "hello",
    "star_type": "4-motel",
    "site": "www.sasasa.asas",
    "service": ["koko", "sili", "solo", "lilo"]"address": "haminja kilo nab"
}][{
    "name": "hi",
    "star_type": "3-apparteman",
    "site": "www.saassaas.aas",
    "service": ["tv", "wan", "hamam", "kolas"],
    "address": "ok"
}]

And this my js code that get error:

$.ajax({
    type: "POST",
    dataType: "json",
    url: 'get_residence',
    data: dataString_h,
    cache: false,
    success: function (respond) {
        //alert(respond);
        $.each(respond[0].name, function (index, value) {
            alert(value);
        });
    },
    "error": function (x, y, z) {
        alert("An error has occured:\n" + x + "\n" + y + "\n" + z);
    }
});
  • 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-25T19:20:18+00:00Added an answer on May 25, 2026 at 7:20 pm

    You are not echoing valid json. Try this:

    $hotel_data = array();
    foreach(...) {
        // .. do stuff
        $hotel_data[] = $data; // add $data to the end of the $hotel_data array
    }
    echo json_encode(array('data' => $hotel_data));
    

    This will wrap all the $data arrays into an array and put it into an object’s data attribute. You can access this data on the js side as follows:

    $.each(response.data, function(i, obj) {
        alert(obj.name);
    });
    

    Note: I am not sure about the php syntax I wrote above, its been a while since I wrote php 🙂

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

Sidebar

Related Questions

I have this JQuery piece of code. I want to see wht php outputs.
In short: For this code: Encoding.ASCII.GetBytes(‚) I want the output to be 130, but
I have this PHP class class myclass{ function name($val){ echo this is name method
I have field like a_b_c_d I want as the output a b c_d, this
I want to output the function name each time it is called, I can
Let's say file test.php looks like this: <?php echo 'Hello world.'; ?> I want
learning Jquery and integrating with PHP - getting there, but have one last challenge
I want to do this: run a command capture the output select a line
I want to output my own object to a STL stream but with customized
I want to output the following string in PHP: ä ö ü ß €

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.