I am using Django for my website. Currently I am using location.reload(); so that while users fill in data and click on a button it will trigger location.reload() and while the whole page reloads, it will execute the Django scripts. But I don't want to reload the whole page to execute the script, I just want to reload the particular <div> using ajax. How can I do that?
{% if userFirstName %}
<div id="topAdminCont" class="left">
<div id="userSection">
<!-- <img src="{% static "assets/images/admin_icon.png" %}" width="20" alt="Admin" class="left" /> -->
<p id="admin" class="right">{{userFirstName}}</p>
<div class="clear"></div>
</div>
<ul id="dropAdmin">
<li><a href="#" id="chngPwdBut">Change Password</a></li>
<li><a href="/authentication/logout">Logout</a></li>
</ul>
</div>
{% else %}
<div id="popCont" class="left username_view">
<p id="signIn"><a href="#">Signin</a></p>
<p>/</p>
<p id="signUp"><a href="#">Signup</a></p>
<div class="clear"></div>
</div>
{% endif %}
Jquery AJAX Handler for above HTML:
function authenticateUser(email, password)
{
$.ajax({
url: '/authentication/login/',
type: 'POST',
cache: 'false',
async: 'true',
data: {
signinEmail:email,signinPwd:password,
},
dataType: "json",
success:function(response){
statusCode = response.statusCode;
if (statusCode == 200)
{
location.reload();
}
}
});
}
location.reloadwill reload well, the location, not just some of the content on the page. Which<div>do you want to refresh?<div>id for this code snippet?