Getting error whle traversing JSON with backbone
I am trying to traverse a JSON response using jquery in backbone, however,
it is giving me error
TypeError: e is undefined @ http://localhost/ scripts/ jquery.js
JSON Data:
{"tweets":[{"url":"http:\/\/twitter.com\/SrBachchan\/status\/378975107009368064","text":"T
1155 -Football the compulsion ... football the meal at meal times ...
despite the Chelsea loss .. but Villa v Madrid on now and great
game","date":"1379189681","user":"\/SrBachchan","id":"145125358"},{"url":"http:\/\/twitter.com\/Mousumimukher13\/status\/378907332711038976","text":"Now
is the #KBC time @SonyTV With Amitabh Bachchan @SrBachchan Just Enjoy
,Watch and Learn
..","date":"1379173522","user":"\/Mousumimukher13","id":"1407612847"},{"url":"http:\/\/twitter.com\/brisha_15\/status\/378907467888873472","text":"@SrBachchan
God do u still watch #KBC alone like frst season or wid
family","date":"1379173554","user":"\/brisha_15","id":"67258128"},{"url":"http:\/\/twitter.com\/NiTiSHmurthy\/status\/378907588978434048","text":"Aww..
This man, very sportive. #KBC
@SrBachchan","date":"1379173583","user":"\/NiTiSHmurthy","id":"18354369"},{"url":"http:\/\/twitter.com\/punkrochelle\/status\/378907593160138753","text":"@SrBachchan
#KBC = Kind Beloved
Contestants.","date":"1379173584","user":"\/punkrochelle","id":"89637264"}]}
My JS file:
$(function() {
FriendList = Backbone.Collection.extend({
initialize: function(){
this.bind("add", function( model ){
view.render( model );
})
}
});
FriendView = Backbone.View.extend({
tagName: 'li',
events: {
'click #btnSearch': 'getFriend',
},
initialize: function() {
this.friendslist = new FriendList;
_.bindAll(this, 'render');
//window.setInterval(this.getFriend, 5000);
},
getFriend: function() {
var hashtag = $('#txtHashTag').val();
if(hashtag.length>0)
{
$.ajax({
type: "GET",
url: "index.php",
dataType:"json",
data: {
name: hashtag
},
success: function(msg){
$.each(msg[0], function(i,item){
alert(i);
// your code ..
});
}
});
}
if(hashtag!=$('#tags').val())
{
$('#tags').append(hashtag);
}
//this.friendslist.add( {name: friend_name} );
},
render: function( model ) {
},
});
var view = new FriendView({el: 'body'});
});
Any idea, what is happening ?
Thanks
No comments:
Post a Comment