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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T11:58:49+00:00 2026-05-20T11:58:49+00:00

In my php page, I’ve three lists ul#line, ul#comment, ul#vote. I’m going to make

  • 0

In my php page, I’ve three lists ul#line, ul#comment, ul#vote.

I’m going to make an ajax call, something like

           $.ajax({
        type: "POST",
        url: "ajax.php",
        data: dataString,

        cache: false,
        success: function(html){
            $("ul#line").append(html);
            $("ul#lineli:last").fadeIn("slow");
    }

Ajax.php is something like

if(isset($line)){
    echo $line;
} elseif(isset($comment)){
    echo $comment;
} elseif (isset($vote)){
    echo $vote;
} else {
   //do nothing;
}

What I want is, if the echoed out HTML is $line, it’ll be appended to ul#line; if it is $comment, it’ll be appended to ul#comment; if it is $vote, it’ll be appended to ul#vote.

The current ajax call appends only at ul#line.

What do I need to change to achieve this??

  • 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-20T11:58:50+00:00Added an answer on May 20, 2026 at 11:58 am

    php

    class DataObject
    {
        public $Type;
        public $Text;
    }
        $json=new DataObject();
    
    if(isset($line)){
        $json->Type="line";
        $json->Text=$line;
        return json_encode($json);
    } elseif(isset($comment)){
        $json->Type="comment";
        $json->Text=$comment;
        return json_encode($json);
    } elseif (isset($vote)){
        $json->Type="vote";
        $json->Text=$vote;
        return json_encode($json);
    } else {
       //do nothing;
    }
    

    javascript

        $.ajax({
        type: "POST",
        url: "ajax.php",
        dataType: 'json',  //add data type
        data: dataString,    
        cache: false,
        success: function(data){
            $("ul#"+data.type).append(data.text);
            $("ul#"+data.type+"li:last").fadeIn("slow");
         }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

if i call a php file via jquery ajax, that contains a script to
Currently I use: RewriteRule ^([^/\.]+)/?$ page.php?page=$1 [L] Which is good for when passing one
I am fetching 2 div's from a page using $.post jQuery AJAX request. Now
I'm creating a small web page using jquery-ui-1.8 which is having a frameset and
I've inherited a site with hundreds of scattered HTML and non-framework PHP files, which
I'm using Jquery colorbox to implement a popup windows. <script> $(document).ready(function(){ $.colorbox({innerWidth:600px, innerHeight:520px, iframe:true,href:/notice.php});
Hi, I know this should be really simple but I am just too new
I have been trying this for so long, but was not able to implement
I have a Button (or a hyperlinkbutton) in Silverlight. I want to open a
Array ( [0] => stdClass Object ( [logtime] => 1305732210 [useragent] => Mozilla/5.0 (Windows

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.