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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T10:34:13+00:00 2026-06-08T10:34:13+00:00

Hi I had just started to use Ajax and am getting an input from

  • 0

Hi I had just started to use Ajax and am getting an input from a textfield (id_title) in html to retrieve information from the database dynamically. It is now working fine when there is input in the textfield from the user, however when there is no input, the database still retrieves the first few records in the database. How can I prevent calling the success function when ‘id_title’ is empty?

Edit:

Perhaps I should add that I’m using Ajax together with the Django framework. When there is no input the first 10 records are retrieved. I’m not sure how to stop sending records to ‘qna/rec_results.html’ when there is no input received from ‘query’ at the django function.

Django Function (Referred function at /qna/question_t_lookup/)

def question_autocomplete_lookup(request):
results = []
model_results = Tags.objects.filter(name__icontains = q)
if request.method == "GET":
    if request.GET.has_key(u'query') :
        value = request.GET[u'query']
        model_results = Question.objects.filter(title__icontains = value)
    else : 
        model_results = Question.objects.all()
else : 
    model_results = Question.objects.all()

paginator = Paginator(model_results, 10)
new_rec_list = paginator.page(1)

return render_to_response('qna/rec_results.html',{'rec_list' : new_rec_list})

AJax Function

 function load_qn_search() {
     $.ajax({
       type: "GET",
       url: '/qna/question_t_lookup/',
       data: {
            query: $("#id_title").val()},
       success: function(data) {              
               $('#ajax_reload_content').html(data);
       },
       statusCode: {
         500: function() {
           alert("Opps! There is a 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-08T10:34:15+00:00Added an answer on June 8, 2026 at 10:34 am

    Thanks to machaku, I was able to come out with this that caught the empty string issue! Thanks alot!

    if len(value.strip()) > 0:
                model_results = Question.objects.filter(title__icontains = value)
            else:
                model_results = [] 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm just getting started with Jenkins CI, and had a question which I'm struggling
I've just started learning SQLite, and had a question. Here is an example of
I had just started using $.on() for a dynamical table for collect passenger personal
So I just recently started learning about how databases work, how to use SQL
I'm a tad confused. I am just getting started with OpenCV and its image
I have just started using JQuery, and i know you can use .click with
I am just getting started with Linq, WPF and Silverlight. I am trying to
Please forgive me if I am somewhat unclear, I am just getting started with
I've just started to use Greasemonkey and am trying to make a userscript that
I just started to use SVN with Xcode and stumbled upon several problems. I

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.