views:

37

answers:

0

Hello,

I'm trying to change my form to ajax form with jquery, but I get an invalid label error in javascript console.

My js code :

<script type="text/javascript">
$(document).ready(function() { 
    $('#jsonForm').ajaxForm({ 
        clearForm: true  ,
        datatype: "json",
         error:function(data){alert('Error:'+data);},
        success:   processJson 
    }); 
  return false;
});

function processJson(string) { 
data = $.parseJSON(string);
alert(data.author + " -> " + data.comment)
}
</script>

In my django view :

   if request.is_ajax():
        return HttpResponse(simplejson.dumps({"author": new_comment.author.username, "publication_date": str(new_comment.publication_date), "comment": new_comment.comment}), mimetype='application/javascript')

So when I validate the form, data are well returned (my alert popup displays the good data) but I have a javascript error that does I cannot treat another code in me processJson function.

javascript error :

Error: invalid label
Source File: http://serv:8000/news/audition/1/
Line: 0, Column: 1
Source Code:
{"comment": "rerthrth", "publication_date": "2010-09-06 16:57:05.959897", "author": "root"}

Thanks for ideas !