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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T12:37:40+00:00 2026-05-30T12:37:40+00:00

EDITED I’m trying to use jquery/ajax to display data returned from a django method.

  • 0

EDITED

I’m trying to use jquery/ajax to display data returned from a django method.

I have a html button called keywordBtn. So when it’s pressed, the updateKeywordSubscribed method will be called.

however, my object is not being returned by django. Is there something wrong with my method?

If successful, the div section name “update” would display the list of words in that json list.

what i have in my html:

<script type="text/javascript">
        $(document).ready(function() { 
            $("#keywordBtn").click(function(e) { 
                updateKeywordSubscribed(e, "#keywords"); 
            });
        });
        function updateKeywordSubscribed(e, keywords) {
            e.preventDefault();
            var option_form = jQuery(e.target);
            $.ajax({
                url : option_form.attr('action'),
                type : option_form.attr('method'),
                data : option_form.serialize(),
                dataType : 'json',
                success : function(response) { alert ('sometext')})
        }
</script>

what i have in my views.py:

def keyword_subscribe(request):
    if 'keyword_input' in request.POST:
    if 'name_input' in request.POST:
        xhr = request.GET.has_key('xhr')
        response_dict = {}
            new_keyword = request.POST['keyword_input']
        username = request.POST['name_input']
        response_dict.update({'keyword_input': new_keyword, 'name_input': username})
        power_keyword = subscribe_keyword(username,keywords)
        if power_keyword:
            response_dict.update({'success':True})
        else:
            response_dict.update({'errors':{}})
            if not username:
                        response_dict['errors'].update({'name_input': 'User ID is required'})
                if not total and total is not False:
                        response_dict['errors'].update({'keyword_input': 'Keyword field is blank'})
        if xhr:
                return HttpResponse(simplejson.dumps(response_dict), mimetype='application/javascript')
            return render_to_response('r2/userprofile_list.html', response_dict)
  • 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-30T12:37:42+00:00Added an answer on May 30, 2026 at 12:37 pm

    I’m doing something similar to what you need in my current project.

    I GET this zipcode view which returns a geojson result or null

    My View:

    def get_zipcode(request, latitude, longitude):
        # Point on a map
        point = GEOSGeometry('POINT(%s %s)' % (longitude, latitude))
    
        try :
            zipcodes = Zipcode.objects.filter(mpoly__contains=point)
            return HttpResponse(zipcodes[0].mpoly.geojson, mimetype="application/json")
        except :
            return HttpResponse(json.dumps(None), mimetype="application/json")
    

    my mimetype is application/json not application/javascript

    My urls:

    url(r'^collision/zipcode/(?P<latitude>(\-|)\d+\.\d+)/(?P<longitude>(\-|)\d+\.\d+)/', 'core.views.get_zipcode', name='collision-zipcode'),
    

    The JS that makes the call and handles the json result

    $.ajax({
        url : '/collision/zipcode/' + latitude + '/' + longitude + '/',
        dataType : 'json',
        type : 'GET',
        success: function(data)
        {
            var paths = coord_to_paths(data.coordinates); 
            var polygon = new google.maps.Polygon({ 
                paths : paths, 
                strokeColor : "#FF7800", 
                strokeOpacity : 1, 
                strokeWeight : 2, 
                fillColor : "#FF7800", 
                fillOpacity : 0.6
            });
    
            polygon.setMap(map);
    
            console.log("adding zipcode polygon");
        }
    });
    

    note that if you are doing retrieving json, if you set the dataType to ‘json’, you should be go to access data in your success function as a JS native.

    if you need to debug what data is actually being retrieved by jquery, do a

    console.log(data);

    and look in your dev console w/i your browser (chrome/ff I dont know if other browsers support this)

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

Sidebar

Related Questions

Edited Question: Trying to use a .dll file from Java using JNA. I've managed
EDITED I'm trying to have source files recompiled without having to specify header files
Question edited for clarity I make an AJAX call, using the $.getJSON() method, and
EDITED QUESTION: I have 2500 rows x 100 columns data in variable named avg_data_models.
--edited for clarity (hopefully) I have an XML file that looks something like this:
edited. Hey, I am trying to write an NSMutableArray to a plist. The compiler
edited: This is what i need: sendpost = function(a,b,c){ return jQuery.post('inc/operations.php', {a:b}, c, json);
Edited........ sorry Sir I was referring this piece of code from Stephen Toub's article..
(Edited to try to explain better) We have an agent, written in C++ for
--- Edited below with some more testing, please read :) --- I'm struggling trying

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.