Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

188
Views
Script returns an empty list data with 200 response, fetching data from django backend

I am working on an autocomplete app that I want users be able to make address search through the backend of Django but somehow the Api doesn't fetch data through the script, why is the payload not showing any data in the log console but rather an empty list?, I have tried calling the data from the browser as in example http://127.0.0.1:8000/search/?address=val , which fetches the json data response with a payload of data of addresses that match my search, but when i pass the url in my javescript it returns an empty data list with a 200 response. My experience in Js is mediocre, since I'm a novice.

<script>
    new Autocomplete('#autocomplete',{

         search : input => {
             console.log(input)
             const url = "/search/?address=${input}"
             return new Promise(resolve => {
                 fetch(url)
                 .then( (response) => response.json())
                 .then( data => {
                    console.log(data)
                     resolve(data.data)
                     
                })
             })
         },
         onSubmit : result => {
             console.log(result)
            window.open('/search/?address=${result}')
         }
     })

     
</script>

here is my search box Html

 <h4>Seacrh for places</h4>
            <div id="autocomplete" class="autocomplete">
                <input class="autocomplete-input"/>
                <ul class="autocomplete-result-list"></ul>
              </div>

my view for search

def search_address(request):
    address =  request.GET.get('address')
    playload = []
    if address:
        fake_address_objs = Address.objects.filter(address__icontains=address)
        
        for fake_address_obj in fake_address_objs:
            playload.append(fake_address_obj.address)
        
    return JsonResponse({'status':200 , 'data': playload })

Returned empty data in the console log

Returned data in browser using http://127.0.0.1:8000/search/?address=v

enter image description here enter image description here

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!