i'm new with expressJS i try to send json data from expressjs app to html
this is my js file :
app.get('/findAccount', function (req, res) {
// Prepare output in JSON format
var data = getClient(req.query['cin']);
res.send(data);
})
this is my HTML views :
<form class="form-group" method="GET" action="http://localhost:3030/findAccount">
CIN : <input class="form-control" id="cin" type = "text" name = "cin" placeholder="AB123456"> <br>
<button id="button">Search</button>
</form>
<div id="client_detail">
</div>
<script>
$('#button').on('click',function(){
$.ajax({
type :'GET',
url:'http://localhost:3030/findAccount'
dataType: 'application/json; charset=utf-8',
success : function(data){
$('#client_detail').html('<h1>Info Client:</h1>');
$('#liste').append('<h3>Address : '+data.address_owner+'</h3>');
$('#liste').append('<p>Nom : '+data.FirstName+'</p>');
$('#liste').append('<p>Prénom : '+data.LastName+'</p>');
$('#liste').append('<p>CIN : '+data.cin+'</p>');
$('#liste').append('<p>Telephone : '+data.tel+'</p>');
$('#liste').append('<p>Addresse : '+data.Addr+'</p>');
}
})
});
</script>
i want when the user click in search the result appear on client_detail div in the same page of the form
via ABDELLAH AYOUB HAMIDI
No comments:
Post a Comment