I have written an ajax call to call an API for post data and fetch after success response and show it in div tag of my respective form, but it gives me complete json {"code":200,"status":"OK","msg":"Login Success"}
, But i just want to show 'msg' part. How can i achieve this? I am doing this on django template.
i tried to do res['msg']
(python key,value stuff) but its not working
<script>
$(document).ready(function(){
var myForm = $('.my-login-form')
myForm.submit(function(e){
e.preventDefault()
console.log('hi')
var formData = $(this).serialize()
$.ajax({
method: "POST",
url: '/login',
data: formData,
success: function(res) {
$('#login-data').html(res);
},
})
})
})
</script>
<form class="my-login-form" action="/login" method="post">
{% csrf_token %}
<div id="login-data"></div>
<div class="field-wrap">
<input type="email" name="login-email" required autocomplete="off" placeholder="Email Id"/>
</div>
<div class="field-wrap">
<input type="password" name="login-password" required autocomplete="off" placeholder="Password">
</div>
<button class="button button-block"/>Login</button>
<div class="forgot"><a class="user-form-toggle" href="#forgot">Forgot Password?</a></div>
</form>