javascript - How do I have an event filter a page? -


i'm working on twitter clone in js + jquery pre-course development program, if obvious fix - let me know! have problem i'm unable solve: "click on username, page returns user's last tweets".

the thing come is, event handler on <a> tag filter page. i'm vastly inexperienced , unclear in how proceed.

any ideas? note- removed code brevity.

$(document).ready(function() {  var $body = $('body'); $body.html();  var stream = function() {     var index = streams.home.length - 1;     while (index >= 0) {         var tweet = streams.home[index];         var $tweet = $('<div class="tweetbody"></div>');         $tweet.text(': ' + tweet.message);         $tweet.appendto($body);         index -= 1;           var link = $('<a>', {             text: tweet.user,             href: '#',         }).prop('outerhtml');         $tweet.html('@' + link + ': ' + tweet.message);      }      }; 

here's <a> tag event:

 //click on username see user's timeline.       $('a').on('click', function() {         console.log("a tag clicked ");         console.log(this);     });        }();      }); //end document ready body 

in on click function perhaps either of 2 things, go page, redirecting new page

    //click on username see user's timeline.       $('a').on('click', function() {         //console.log("a tag clicked ");         //console.log(this);         window.location = '/some_file.php?get_tweets='+tweet.user;     }); 

or, use ajax call same:

    //click on username see user's timeline.       $('a').on('click', function() {         //console.log("a tag clicked ");         //console.log(this);         $.ajax({             type: "get",             url: "/some_file.php",             data: {                'user' : tweet.user             },             success: function(msg) {                 $body.html(msg);         });     }); 

in both cases some_file.php should format content.


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -