Currently, I am in the process of developing a Single Page Application (SPA) utilizing both Django and JavaScript. On my home page, there are two buttons: "Sign Up" and "Sign In." My objective is for an AJAX call to redirect to the sign-up URL upon clicking the sign-up button. Below, you can find the code snippets I have been working with:
JavaScript Code
$('#id_register').click(function(){
$.ajax({
url: 'register',
method: "GET",
success: function(data){
console.log(data)
},
error: function(error){
console.log(error)
}
})
})
HTML Code
<div class="banner">
<div class="content">
<h3 id="home">Feeling Hungry?</h3>
<h4 id="home_para">Order right now!</h4>
<div>
<button id="id_sign" type="button">Sign In</button>
<button id="id_register" type="button">Sign Up</button>
</div>
</div>
</div>
</body>
Although the data retrieval is successful, the redirection to the designated URL is not occurring as expected.
Here is an excerpt from my urls.py file for reference:
urlpatterns =[
path('register', RegisterView.as_view()),
path('login', LoginView.as_view(), name="login"),
path('', HomeView.as_view(), name="home")
]
Any assistance provided would be greatly appreciated.