I am trying to learn backbone.JS using WAMP server. when I am trying to retrieve the data from database using fetch function, I couldn't convert the data extracted from database into JSON objects. So here I used Index.php for client side and views.php for server side. Name of my database is dss.Thanks in advance. So here is my code
index.php
<!doctype html>
<html>
<title>
backbone example
</title>
<body>
<script src="jquery-1.9.1.js"></script>
<script src="underscore.js"></script>
<script src="backbone.js"></script>
<div id="container">
<h1>
HELLO
</h1>
<div id="page">
</div>
</div>
<script>
var User=Backbone.Collection.extend(
{
url:'backbone sample/users'
}
);
var UserList=Backbone.View.extend(
{
el:'#page',
render:function()
{
var that=this;
var users=new User;
users.fetch({
success:function()
{
alert('success');
}
}
);
}
}
);
var router=Backbone.Router.extend(
{
routes:
{
'':'home'
}
});
var userList=new UserList();
var rou=new router();
rou.on('route:home',function(){
userList.render();
});
Backbone.history.start();
</script>
</body>
</html>
users.php
<?php
$request_method = strtolower($_SERVER['REQUEST_METHOD']);
$a=$_GET['id'];
mysql_connect("localhost", "root", "") or die("connection error");
mysql_select_db("dss") or die("db error");
$results= mysql_query("select * from subscribers where EmailId='$a'");
?>