I have this code , it works when I put it in the same file, but I must separate the html from the javascript, now my problem is how can the function know the #r so it can put the data in it?
<button id="charger">GET Data</button>
<div id="r">Click</div>
<script src="jquery.js"></script>
<script>
$(function() {
$('#charger').click(function() {
$.getJSON('url', function(donnees) {
$('#r').html('<p><b>Name</b> : ' + donnees.name + '</p>');
$('#r').append('<p><b>Message</b> : ' + donnees.msg + '</p>');
$('#r').append('<p><b>id</b> : ' + donnees.Type + '</p>');
});
});
});
</script>
and my modification so far is : page.html: ...
<p class ="submit"><input type="submit" id="charger" value="OK" onclick="test();"></p>
<div id="r">Your data : </div>
and the js file :
function test() {
$('#charger').click(function() {
$.getJSON('url', function(donnees) {
$('#r').html('<p><b>Name</b> : ' + donnees.name + '</p>');
$('#r').append('<p><b>Message</b> : ' + donnees.msg + '</p>');
$('#r').append('<p><b>id</b> : ' + donnees.Type + '</p>');
});
});
}
in the console , the function works , but it doesn't show me the data ..