Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 7th, 2012  |  syntax: None  |  size: 1.97 KB  |  hits: 11  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Why my Jquery AJAX fail executing some methods upon succeed?
  2. $(document).ready(function(){
  3.  
  4.     $(function() {  
  5.         $("#update_status_btn").click(function() {
  6.            var user_id = $("#update_status #user_id").val();
  7.            var status = $("#update_status #status").val();
  8.            var dataString = 'user_id='+ user_id + '&status=' + status;
  9.  
  10.                update_status('profile/update_status', dataString);
  11.            return false;
  12.                });  
  13.     });
  14.  
  15.  
  16.  
  17.  
  18. });
  19.  
  20. function update_status(method_url, dataString)
  21. {
  22.         $.ajax({
  23.           type: 'POST',
  24.           url: method_url,
  25.           data: dataString,
  26.           cache: false,
  27.           success: function() {
  28.               //the following methods won't executed :-(
  29.                 update_timeline('profile/get_user_timeline', '#user_timeline ul');
  30.                 update_timeline('profile/get_home_timeline', '#home_timeline ul');
  31.           }
  32.         });
  33. }
  34.  
  35. function update_timeline(method_url, target)
  36. {
  37.         //get home timeline
  38.         $.ajax({
  39.           type: 'GET',
  40.           url: method_url,
  41.           dataType: 'json',
  42.           cache: false,
  43.           success: function(result) {
  44.             $(target).empty();
  45.             for(i=0;i<result.length;i++){
  46.                 $(target).append('<li><article><img src="'+ result[i]['user']['profile_image_url'] +'"><a href="">'+ result[i]['user']['screen_name'] + '</a>'+ linkify(result[i]['text']) +'</li></article>');
  47.             }
  48.           }
  49.         });
  50. }
  51.  
  52.  
  53. function linkify(data)
  54. {
  55.     var param = data.replace(/(^|s)@(w+)/g, '$1@<a href="http://www.twitter.com/$2" target="_blank">$2</a>');
  56.     var param2 = param.replace(/(^|s)#(w+)/g, '$1#<a href="http://search.twitter.com/search?q=%23$2" target="_blank">$2</a>');
  57.     return param2;      
  58. }
  59.        
  60. $.ajax({
  61.  type: 'Post'
  62.  url: method_url,
  63.   data: dataString,
  64.  cache: false,
  65.  success: function() {},
  66.  error: function (jqHxr, statusText) {
  67.    //jqXhr.responseText holds the response sent from the server
  68.                 }