A.Lang A.Lang - 2 months ago 7
Ajax Question

Load two divs with a single Ajax call

I'm trying to use load() to load two divs

#follow-x
and
#follow-y
ajaxly with a click of a button.This is what I have tried in
success
function,but doesn't work,but works if I remove one of the function,so it loads only one div but I want it to load both.Thanks in advance

$('#follow').click(function(){

$.ajax({

type: "POST",
url: "{% url 'follow_class' %}",
data: {'pk': '{{class.pk}}' , 'csrfmiddlewaretoken': '{{ csrf_token }}'},
dataType: "json",
success: function(){
$('#follow-x').load("{% url 'class_details' %} #follow-x");}
function(){
$('#follow-y').load("{% url 'class_details' %} #follow-y");}

});
});
</script>


Dont mind the tags
{}
I'm using Django

M B M B
Answer

only the first function is being called on success

put both statements in one function

$('#follow').click(function(){

          $.ajax({

                   type: "POST",
                   url: "{% url 'follow_class' %}",
                   data: {'pk': '{{class.pk}}' , 'csrfmiddlewaretoken': '{{ csrf_token }}'},
                   dataType: "json",
                   success: function(){
                       $('#follow-x').load("{% url 'class_details' %} #follow-x");                        
                       $('#follow-y').load("{% url 'class_details' %} #follow-y");
                    }

              }); 
        });