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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T19:42:11+00:00 2026-06-12T19:42:11+00:00

I have a form that triggers an ajax request to a view after the

  • 0

I have a form that triggers an ajax request to a view after the user tabs out of the ‘address’ field. It retrieves the zip code and then populates pickups with the same zip. The problem is that if there are any form errors is that the drop down with the results I generate from my get_pickups view is lost. How can I keep it so that even on form errors it will keep the results

def get_pickups(request):   

    if request.is_ajax():   
        # Get available pickup dates based upon zip code
        zip = request.POST.get('zip',None)
        routes = Route.objects.filter(zip=zip).values_list('route',flat=True)       

        two_days_from_today = date.today() + relativedelta(days = +2)

        submitted_from = request.POST.get('template',None)
        if submitted_from == '/donate/':
            template = 'donate_form.html'
            results = PickupSchedule.objects.filter(route__in=routes,date__gt = two_days_from_today, current_count__lt=F('specials')).order_by('route','date')
        else:
            template = 'donate-external.html'
            results = PickupSchedule.objects.filter(route__in=routes,date__gt = two_days_from_today, current_count__lt=F('specials')).order_by('date')          

        return render_to_response(template,{ 'zip':zip, 'results':results}, context_instance=RequestContext(request))

my ajax call via jquery:

$.ajax({
        type: "POST",
        url:"/get_pickups/",
        data: {
        'zip': zip,
        'template':template
        },
        success: function(data){            

                results = $(data).find('#results').html()           
                $("#id_pickup_date").replaceWith("<span>" + results + "</span >");      
        },
        error: function(){
            alert("Error");
        }
  • 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-12T19:42:12+00:00Added an answer on June 12, 2026 at 7:42 pm

    I can think of two approaches:

    1. Attach the contents of that dropdown to your POST and return it along with the data in the other fields if there’s an error (downside: added complexity in server code)
    2. Use javascript to check if that zip field is non-empty on page load/reload. If it’s not empty (e.g. error return), call your ajax lookup for that dropdown (downside: duplicate calculations)

    I’d use whichever solution you feel most skilled with (python/django or javascript)

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

Sidebar

Related Questions

I have a page that loads an HTML form via a $.ajax request. The
I have a simple form that triggers an ajax call but as soon as
I have a form that requires a physical address. Once the user enters the
I currently have form that checks if a user has unsubmitted changes when they
I have a form that I'm submitting through AJAX. The form includes many fields,
I have a form that the user submits and returns a result, but it
I have a form that i want an administrator to fill out, then click
I have a problem, when submitting a form all active ajax request fail, and
I have the following bit of code that triggers some ajax events on a
I have a bit of jquery that makes an ajax request to a script

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.