I want to get data stored in mysql using jquery and populate it on a web page dynamically. I tried this code but it isnt working.
<html>
<head>
<script src="jquery-1.7.2.js"></script>
</head>
<body>
<pre>
<script>
var url = "https://natiweb-natiweb.rhcloud.com/game.php";
$.getJSON(url,function(data){
$.each(data,function(i,user){
alert("inside JSON");
alert(user.appname+"\n"+user.applink);
var a = document.createElement('a');
var linkText = document.createTextNode(user.appname);
a.appendChild(linkText);
a.title = linkText;
a.href = user.applink;
document.body.appendChild(a);
var b = document.createElement('br');
document.body.appendChild(b);
});
}
);
</script>
</pre>
</body>
</html>
It never executes getJSON query. i dont know whats wrong. "Inside JSON" doesnt get printed. I tried writing same script code using a dedicated js file and it worked. I want it to work inside body as i have to create links dynamically by getting links from mysql.