2

Possible Duplicate:
django file upload from json

Hi am using the following ajax upload from the template but i do not get a response from django view.What is wrong here..i do not see any alert

function ajax_upload(formid)
{
var form = $(formid);
form.ajaxSubmit({
  dataType:  'json',
  success:   function (data) {
  alert("Hereeeeeeee");
  if(data.status == '1')  
  {
     alert("Uploaded Successfull");
  }
  else 
  {
     alert("Uploaded UnSuccessfull :(");
  }
  }
} )   ; 
}

EDIT Django:

  def someview(request):
      response_dict={'status':1}
      logging.debug("seen") //This is seen in the logs
      return HttpResponse(simplejson.dumps(response_dict), mimetype='application/javascript')

EDIT1

Please also for complete source code look at django file upload from json

Community
  • 1
  • 1
Rajeev
  • 44,985
  • 76
  • 186
  • 285

3 Answers3

0

Check that someview added to urls.py.
Check that {% csrf_token %} added to form

beholderrk
  • 730
  • 8
  • 17
  • Yes both are taken care of..If i put a log before return i do see it.Please see the edit in the question – Rajeev Jul 18 '12 at 11:36
0

It's rather impossible you will see that log, hence this is a python syntax error:

response_dict{'status':1}

and should be:

response_dict = dict(status=1)

or:

response_dict = {'status':1}

or:

response_dict = dict()
response_dict['status'] = 1

or:

response_dict = dict()
response_dict.update({'status':1})
Hedde van der Heide
  • 21,841
  • 13
  • 71
  • 100
0

From your code:

form.ajaxSubmit({
  dataType:  'json',
  success:   function (data) {
    alert("Hereeeeeeee");

Your callback executes on 'success', so we can narrow down the failure to the django view side. Assuming everything is syntactically correct, my best guess is that since you're returning json data, your response mimetype should be:

mimetype='application/json'.

If that doesn't work, I would suggest using Firebug on Firefox or Developer Tools on Chrome to look at the server response. You should be able to see a django stacktrace there.

bratface
  • 76
  • 4
  • I had tried this but i still do not see a response i can even do a render to response..Niot sure what the issue is – Rajeev Jul 18 '12 at 12:26