I have a PHP file that creates a JSON text of my MySQL data.
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<title>Sample Page</title>
<script>
var settings = {
"async": true,
"crossDomain": true,
"url": "http://www.hotel1.com/Experiment/Api/Json1.php?ID=1",
"method": "GET"
}
$.ajax(settings).done(function (response) {
console.log(response);
console.log(response.something.something)
});
</script>
Above you can see my code
[
{
"Worker1": {
"ID :": "1",
"Username": "Tony"
}
}
]
Above you can see my JSON text that is being printed. My problem is I want to know how to select ID from the JSON text in JavaScript. As shown above. When I try to say response.Worker1.ID it give me an error saying ID is undefined.
Can someone help me fix my mistake?