Issue
I am trying to create a SPA, using django and javascript, I have a home page with two buttons on it (Sign up and sign in), I want that when signup button is clicked, ajax redirects towards signup url Here is my code
js
$('#id_register').click(function(){
    $.ajax({
        url: 'register',
        method:"GET",
        success: function(data){
            console.log(data)
        },
        error: function(error){
            console.log(error)
        }
    })
})
Here is my html
<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>
It is successfully returning me the data but not redirecting towards the required url.
here is my urls.py
urlpatterns =[
    path('register', RegisterView.as_view()),
    path('login', LoginView.as_view(), name="login"),
    path('', HomeView.as_view(), name="home")
]
I will be very thankful for the help
                        
                        Solution
try using this
$('#id_register').click(function(){
    $.ajax({
        url: '/register/',
        method:"GET",
        success: function(data){
            console.log(data)
        },
        error: function(error){
            console.log(error)
        }
    })
})
then the urls.py
path('register/', RegisterView.as_view()),
                        
                        Answered By - ShiBil PK Answer Checked By - David Goodson (PHPFixing Volunteer)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.