Nima
Nima

Reputation: 530

django JSON response does not attached to jQuery post sucess

I use Ajax post method to send my form information to django and after a time consuming process results get back to the ajax post . the problem is that when django view return result It apear on web browser screen and seems it dose not bound to ajax post success method here is my Ajax post method :

 $('#LearnSubmit').on('click',function(e){
   e.preventDefault       
   var form =$('#ParameterForm');
   console.log("waiting ajax");
   $.ajax({
      type :"POST",
      url  : $form.attr('action'),
      data : $form.serialize(),
      success : function(data,status){
        console.log('lablablab');
        console.log(data)
    }
})

}) ;

according to my ajax post method after djang oview return result "lablablab" and data should print in console but returing result is printed on screen could time consuming django view cause that ?

here is my django view :

  def NNLearnSin(request):
    context = RequestContext(request)
    if request.method=='POST':
         response_dict = // a time consuming process here 
         return JsonResponse(respons_dict)

Upvotes: 0

Views: 200

Answers (1)

rojoca
rojoca

Reputation: 11190

It sounds like your form submit button is actually submitting the form and the click event is not called. Looking at your code I would say that e.preventDefault should be e.preventDefault() otherwise the default form submit is not "prevented".

Upvotes: 1

Related Questions