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

  • Home
  • SEARCH
  • 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 8239489
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T20:09:53+00:00 2026-06-07T20:09:53+00:00

Trying to output html php through JSON for an ajax website. php: $return =

  • 0

Trying to output html php through JSON for an ajax website.

php:

$return = "<div id='content'><ul class='allitems'>";
while($row = mysql_fetch_array($result)){
    $return .= "<li class='items'>" . "<div class='itemheading'><div  class='controls'> <span class='votes'>" . $row['votes'] . "</span>";
    $return .= "<form class='actions' action='index.php' method='POST'><input type='hidden' name='id' value='{$row['id']}'/><input type='submit' class='button plus' value='+1' /></form>";
    $return .= "<form class='actions' action='index.php' method='POST'><input type='hidden' name='id-' value='{$row['id']}'/><input type='submit' class='button minus' value='-1' /></form>  ";
    $return .= "<form class='actions' action='index.php' method='POST'><input type='hidden' name='idDel' value='{$row['id']}'/><input type='submit' class='button delete' value='X' /></form>  ";
    $return .= "</div><span class='title'>" . $row['name'] . "</span></div><span class='infotext'>". $row['infotext'] ."</span></li>";
}
$return .= "</ul></div>";
echo json_encode($return);

The output if you go to this php page has slashes (\/) all over the place eg. <\/span><\/form> <\/div>Make the app look all nice<\/span>and doesnt output as regular html.

this is the code for the ajaxpage that willshow the putput:

    <script id="source" language="javascript" type="text/javascript">

  $(function () {
    $.ajax({url: 'retrieve.php', dataType: 'json'}).done(function(data) {


            var html = data[3];

            $('#output')
                .append("<b>id: </b>"+html)


    });
});
  </script>

problem with this is that it outputs < when var html = rows[0]; d when [1] ect. only showing 1 character at a time.

How do I see all the html in one go and as actual html code?

  • 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-07T20:09:55+00:00Added an answer on June 7, 2026 at 8:09 pm

    JSON returns things in an array like manner (im new too it as well so im not exactly sure) so youhave to make all that html one object in the array. Below I have set it to be referened using ‘html’ in an associative array.

    on the php page change this echo json_encode($return); to this
    echo json_encode(array('html' => $return));

    On the ajax page you will need to change it only a little.

    replace:

    var html = data[3];
    
                    $('#output')
                        .append("<b>id: </b>"+html)
    

    with:

    var html = data['html'];
    
                $('#content')
                    .append(html)
    

    or to make it neater you dont even have to make a variable for html you can just get it straight from the JSON array:

            $('#content')
                .append(data['html'])
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to format some html output from my db using php and
I am trying to output html with jQuery. $('body').append(' <div> <div> <div></div> </div> </div>
I have this i'm trying to output in PHP: $this->Js->buffer( var searchTerm = $(this).html();
I'm trying to output the following html using an html helper in asp.net mvc
I'm trying to use XSL-stylesheets in order to transform some generated XML-data to HTML-output.
Ok, here's what I'm trying to do... given this razor code @using(Html.WriteLater()) { output
I am trying to output JSON directly in my Razor view. The object being
I am trying to output the comments of a facebook page in PHP. For
I m trying to output introtext of article selected by their alias <?php $db
I'm trying to add extra tags to the PEAR package BBCodeParser http://pear.php.net/package/HTML_BBCodeParser/docs/latest/li_HTML_BBCodeParser.html , to

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.