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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T01:02:51+00:00 2026-06-07T01:02:51+00:00

I am trying to return a json response for an ajax request with django.

  • 0

I am trying to return a json response for an ajax request with django. Json response is a python dictionary serialized. I am sure that dictionary contains enough data, but it doesn’t arrive to client side.
Server side I have this python routine:

def routine(request):
    response_dict = {}
    f = open("output.txt", "r")
    for line in f:
        line.strip('\n ')
        (key, val) = line.split('\t')
        if re.search("^[a-zA-Z][a-zA-Z0-9]*$", key) != None:
            if re.search("^[0-9]+$", val) != None:
                response_dict[key] = val
    f.close()
    json_response = json.dumps(response_dict)
    return HttpResponse(json_response, mimetype='application/json')

Client side I have this javascript+jQuery routine (EDITED below, see that version):

$.postJSON('ajax/routine', '', function(data) 
      {
        console.debug(data);
        console.debug(data.result);
        $("#result").html(data.result);
      });

postJSON is a jQuery plugin that does a POST ajax request, the code is the following:

$.postJSON = function(url, data, callback) {
    return jQuery.ajax({
    'type': 'POST',
    'url': url,
    'contentType': 'application/json',
    'data': JSON.stringify(data),
    'dataType': 'json',
    'success': callback
    });
};

No output is written neither in console nor in tag identified with “result”.

Edit now it is returning 200 Http status code, and 124 as data.result . In the server I debugged and json.dumps works flawlessly.

Edit2 I’ve edited my jQuery/javascript code:

$.postJSON('ajax/routine', '', function(data) 
      {
        array = {};
        for(key in data)
          {
            array = key + " " + data[key];
          }
        $("#result").html(array);
      });

I’ve tested it under Firebug and response arrives to client but: 1) with small array (1 element) it is printed out 2) response makes me crash both Chromium developer tools and Firebug (when opening JSON tab, in response tab I get only a piece of response and the message “Firebug response size limit has been reached. Click here to open the entire response in a new Firefox tab”.

Thanks

  • 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-07T01:02:58+00:00Added an answer on June 7, 2026 at 1:02 am

    $.postJSON is about POSTing data, which is not what you need here since you’re obviously not posting anything (and don’t handle anythin posted in your view neither). Using $.getJSON instead is probably the first thing to do (http://api.jquery.com/jQuery.getJSON/). This would also avoid any problem with django’s csrf token

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

Sidebar

Related Questions

I'm trying to return a JSON response from a Django view call via an
I am trying to create an ajax request to a WebService that returns data
Hi i am trying to handle an ajax json response here is my code
EDITED I'm trying to use jquery/ajax to display data returned from a django method.
I'm trying to return json content read from MySQL server. This is supposed to
i am noticing a error when im trying to return json from a fetchAll.
I am trying to return two json sets from java which each contain key/value
I am trying to return a JSON object from an aspx page using Jayrock.JSON.
I'm currently trying to return multiple JSON objects in one of my controllers as
I'm trying to return use a JSON object with handlebars. Making a small todo

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.