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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T23:41:20+00:00 2026-06-16T23:41:20+00:00

I am using this bit of PHP to return a chunk of html: if

  • 0

I am using this bit of PHP to return a chunk of html:

if ($action = "update")
    {

        connect_db();

        $query = mysql_query("SELECT * FROM convo ORDER BY date ASC") or die (mysql_error());

        while($row = mysql_fetch_array($query))
        {
            $output = $output . '<p>';
            $output = $output . '<b>From:</b> ' .$row['from'];
            $output = $output . ' <b>To:</b> ' .$row['to'];
            $output = $output . ' <b>Message:</b> ' .$row['content'];
            $output = $output . "<br />";
            $output = $output . '</p>';
        }

        //htmlentities($output);

        header('Content-Type: application/json');
        echo json_encode( $output );
    }

And then insert it into a <div> with this bit of jQuery:

function update(){

        $.ajax({
            type: "GET",
            url: "actions.php",
            data: {  
                'action': 'update'
                },
            dataType: "json",
            success: function(data)
            {
                console.log('update called');
                console.log( data);
                $('#history').text( data );

                //$('#status').text('sent!');
            }
        });             

        setTimeout(update, 5000);
    }   

The ajax call works and returns the correct html however when inserted it is not formatted, I can see all the html code in the browser. See example picture: browersoutput

Should be using something other than .text?

  • 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-16T23:41:21+00:00Added an answer on June 16, 2026 at 11:41 pm

    You are creating JSON in php, and using json dataType for no reason when you want html.

    Just output the html string in php and remove the dataType:'json from AJAX.

    echo  $output ;
    

    Then instert using html() method

     $('#history').html( data );
    

    The load() method is ideal for your case. It is a $.ajax shortcut method. You could replace all the AJAX you have with:

     $('#history').load("actions.php", { 'action': 'update'},function(){
         console.log('new content inserted now')
     })
    

    API reference: http://api.jquery.com/load/

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

Sidebar

Related Questions

Looking to do a bit of refactoring... Using NHibernate I have this query currently
Using this example: http://www.w3schools.com/php/php_ajax_database.asp I have set up a table echoing from database. I
I am using this bit of code successfully: $(window).bind('resize',function() { window.location.href = window.location.href; });
I have a costume class called Region and I am using this bit of
Currently I'm using this minor bit of javascript to remove a small list of
I have this bit of code: using System; using System.Collections.Generic; using System.ComponentModel; using System.Data;
I'm a bit stuck on this - I am using a Wordpress shortcode with
This is my first time using an external library, and I'm a bit nervous
I am using ubuntu 12.04 on 64 bit machine, I have this simple C
I've been trying to figure this one out for a bit using patterns or

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.