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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T13:43:41+00:00 2026-05-26T13:43:41+00:00

Right now, I am working on a web project in PHP and for the

  • 0

Right now, I am working on a web project in PHP and for the next phase, we’re going to change our original post back option to AJAX. Last week, we implemented a threaded comments page which we sent comments into mySQL with php, this week we want that to happen asynchronously instead of using postbacks… i’m kinda confused how to use this

we are expected to use the jQuery library and obviously to use AJAX. I have used AJAX.net toolkit, but that wasnt much AJAX, so i’m kind of confused how to make the transition. heres some code if you want it…

 if($_POST){

//Connection string to get to database
$host = 'localhost'; 
$user = 'user'; 
$password = 'pw'; 
$dbh = new mysqli($localhost, $user, $password, "database schema name");

//Prpared statement for user inpur, prevent sql-injection attacks
$isEntered = $_POST['txt_isEntered'];
$stmt = $dbh->prepare("INSERT INTO tbl_Comment (comment, project_title, parent_comment_id) VALUES (? , ? , ?)");
$stmt->bind_param('ssi', $prevComment, $prevAssignment, $parentID);

//if this is for parent level comments
if(strcmp($isEntered, 'yes') == 0){

    $prevComment = $_POST['txt_comment'];
    $prevAssignment = $_POST['txt_assignment'];
    $parentID = $_POST['txt_pid'];


    $stmt->execute();
}
    if(strcmp($isEntered, 'nested') == 0){

    $prevComment = $_POST['txt_nestedComment'];     

    $prevAssignment = $_POST['txt_assignment'];
    $parentID = $_POST['txt_pid'];

    $stmt->execute();

}

 //redirect page 
 header("Location: viewComments.php");
 exit();

}

this is at the beginning of the page and uses a post, redirect, refresh method (in case if users refresh the page, it does not repeat insert command since it will redirect itself)

heres the code that gets info…

            echo "<form action=\"viewComments.php\" method = \"post\">";
                echo "<textarea rows='3' cols='20' name='txt_nestedComment'>Enter comment here...</textarea>" . "</br>";
                echo "<input tpye = 'text' name = 'txt_assignment' value = $assignment class = 'hidden'>";
                echo "<input tpye = 'text' name = 'txt_pid' value = $cid class = 'hidden'>";
                echo "<input tpye = 'text' name = 'txt_isEntered' value = 'nested' class = 'hidden'>";
        echo "<button type='submit'>Submit Comment</button>" ;
        echo "</form>";

when the user presses the insert button, the page redirects itself and goes to the previous code, and then inserts stuff. any ideas where to start converting this into AJAX? If you need more code, please ask! Thanks!

  • 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-26T13:43:42+00:00Added an answer on May 26, 2026 at 1:43 pm

    With Ajax you get get rid of the form. You will be sending the values to a script via javascript.

    $.ajax({
      type: "POST",
      url: "addcomment.php",
      data: "assignment=" + $('txt_assignment').val() + "&pid=" + $('txt_pid').val() + "Boston",
      success: function(newTableRowCodeFromServer){
        $("#commmentsTable").append(newTableRowCodeFromServer);
      } 
    });
    

    This will send and proces the data then the addComments will result in response that generates the row to insert at the end of the current table or comment display.

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

Sidebar

Related Questions

I'm working on a project in Ruby right now that is essentially a web-app.
Right now I'm working on a web application that receives a significant amount of
I'm currently working on web application using VB in ASP.NET. Right now I have
Right now I am working on a stub of a project. In the course
Right now a project I'm working on has reached a level of complexity that
I am working on a project right now that involves receiving a message from
I'm working on a project right now in which I need to automate animated
I am working on a new PHP project now, this time I want to
I'm working on a multi-project, and right now I have a structure that resembles
I am working on a project right now and I am using the NOW()

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.