<script type="application/javascript">
function loadJSON()
{
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
// Parse the JSON data structure contained in xmlhttp.responseText using the JSON.parse function.
var JSONObject = JSON.parse(xmlhttp.responseText);
// The JSONObject variable now contains the data structure and can be accessed as JSONObject.firstName and
// JSONObject.lastName. Assign the object members to the DOM elements FirstName and LastName so that they get
// displayed on the page
document.getElementById("FirstName").innerHTML = JSONObject.firstName;
document.getElementById("LastName").innerHTML = JSONObject.lastName;
}
}
xmlhttp.open("GET","JSON.txt",true);
xmlhttp.send();
}
</script>
<title>JSON and AJAX</title>
</head>
Prince
Vivian
Update Name Click this button to update the page
</html>
et le format json "JSON.txt" suivant:
{"firstName": "Isabelle", "lastName": "Solomon"}
j'ai essayer de l'implémenter mais ça ne marche pas, je ne sais pas si vous pouvez m'aidez la dessus.