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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T02:44:13+00:00 2026-05-23T02:44:13+00:00

Hi guys I am rather new at AJAX programming but I have managed to

  • 0

Hi guys I am rather new at AJAX programming but I have managed to get part of my code to function the way I would like it to. I hope you guys can help me get through this roadblock and I want to thank you guys ahead of time for all the help i have received just buy reading through this site.

Currently, I have:

  1. A form with two input fields that (onClick) sends data via AJAX to a php script which returns an array of bus details.

  2. I have managed to append the bus info to the $(‘#main’) div successfully.

what i need help with…

The first AJAX call works and so does any call afterwards. However, every time i submit the form again, after the first success call has been made, the results do not update with the new information. Instead the new search results are added to the end of the previous ones and I end up with a long list of buses rather than just the ones I specified in the search field.

<script type="text/javascript">
$(document).ready(function() {
$("#date").datepicker({
   showOtherMonths: true,
   selectOtherMonths: true,    
   changeMonth:true,
   changeYear:true,
   numberOfMonths:1,
   showButtonPanel:true,
   showOn: "button",
   buttonImage: "images/calendar.gif",
   buttonImageOnly: true,
   dateFormat:'yy-mm-dd'
});

$('#search1').click(function(){
    var date = $('#date').val();
    var location = $('#location').val();
    var datastring = 'date=' + date + '&location=' + location;
    $.ajax({
        type: "POST",
        cache: "true",
        url: "search.php",
        datatype:"json",
        data: datastring,
        success: function(data){
            $main = $('#main');

            for ($i = 0, $j = data.bus.length; $i < $j; $i++) {

                  $("#main").append('<div>' + data.bus[$i].number + '</div>');
                  $("#main").append('<div>' + data.bus[$i].capacity + '</div>');
                  $("#main").append('<div>' + data.bus[$i].time + '</div>');
                  $("#main").append('<div>' + data.bus[$i].seats + '</div>');
              }
        }
    });

    return false;
     });
});

</script>

This is how the html looks when I submit the form three times with different search parameters:

2
55
09:00:00
20

4
54
09:00:00
43

3
55
09:00:00
16

How do I update the first call so that I only end up with one set of bus details that can be refreshed/updated?

—Solved——–
This is what I ended up doing:

  1. on AJAX success:

            success: function(data){
    
            $('#main').html('')
    
            for ($i = 0, $j = data.bus.length; $i < $j; $i++) {
                var html = '<div id="bus_detail">';
                html +=  '<div id="capacity">' + data.bus[$i].capacity + '</div>';
                html +=  '<div id="time">' + data.bus[$i].time + '</div>';
                html +=  '<div id="seats">' + data.bus[$i].seats + '</div>';
                $('#main').append(html);
              }
        }
    

thanks @mightyplow for the tip

  • 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-23T02:44:14+00:00Added an answer on May 23, 2026 at 2:44 am

    another way would be to use a $(‘main’).html(”) before the appendings to clear the main-div before adding the new information =)

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

Sidebar

Related Questions

Rather basic question here guys. Basically I have code like this: public SuperPanel() {
I agree with this answer and like it but i really would rather have
I rather like the prototype way of programming and have been trying to understand
Guys, I’ve been writing code for 15+ years, but managed to avoid Web Development
Hi guys I wrote this code and i have two errors. Invalid rank specifier:
Guys is there a way to pass a Annotation as a direct parameter (rather
Ok guys, I'm really new at python (and programming itself) so sorry for my
guys, I am rather new to python and learning it to build a gui
Hey guys, I have a UL like so: <ul id=list> <li class=something> <div class=btns
We have rather large code base (150+ projects, 400000+ lines of Java code, some

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.