
Untitled
By: a guest on
May 7th, 2012 | syntax:
None | size: 1.97 KB | hits: 11 | expires: Never
Why my Jquery AJAX fail executing some methods upon succeed?
$(document).ready(function(){
$(function() {
$("#update_status_btn").click(function() {
var user_id = $("#update_status #user_id").val();
var status = $("#update_status #status").val();
var dataString = 'user_id='+ user_id + '&status=' + status;
update_status('profile/update_status', dataString);
return false;
});
});
});
function update_status(method_url, dataString)
{
$.ajax({
type: 'POST',
url: method_url,
data: dataString,
cache: false,
success: function() {
//the following methods won't executed :-(
update_timeline('profile/get_user_timeline', '#user_timeline ul');
update_timeline('profile/get_home_timeline', '#home_timeline ul');
}
});
}
function update_timeline(method_url, target)
{
//get home timeline
$.ajax({
type: 'GET',
url: method_url,
dataType: 'json',
cache: false,
success: function(result) {
$(target).empty();
for(i=0;i<result.length;i++){
$(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>');
}
}
});
}
function linkify(data)
{
var param = data.replace(/(^|s)@(w+)/g, '$1@<a href="http://www.twitter.com/$2" target="_blank">$2</a>');
var param2 = param.replace(/(^|s)#(w+)/g, '$1#<a href="http://search.twitter.com/search?q=%23$2" target="_blank">$2</a>');
return param2;
}
$.ajax({
type: 'Post'
url: method_url,
data: dataString,
cache: false,
success: function() {},
error: function (jqHxr, statusText) {
//jqXhr.responseText holds the response sent from the server
}