這裏是我的一塊的Javascript:jQuery AJAX調用+ PHP:它是如何工作的?
// TWITTER
var twitter =
{
uid: '<?php echo $user['uid']; ?>',
twitter: '<?php echo $user['twitter']; ?>'
};
$.ajax({
type: "POST", // Using the POST method
url: "/ajax/social/pull/twitter", // The file to call
data: twitter, // Our data to pass
beforeSend: function(){
$('#ajax-pull-twitter').html('<a rel="nofollow" target="_blank" href="#"><img style="position: relative; top: 4px; left: 50%;" src="/www-static/assets/images/ajax-loader.gif"></a>');
},
success: function(data) {
$('#ajax-pull-twitter').hide().fadeIn(3000).html(data);
}
});
// YAHOO
var twitter =
{
uid: '<?php echo $user['uid']; ?>',
yahoo: '<?php echo $user['yahoo']; ?>'
};
$.ajax({
type: "POST", // Using the POST method
url: "/ajax/social/pull/yahoo", // The file to call
data: twitter, // Our data to pass
beforeSend: function(){
$('#ajax-pull-twitter').html('<a rel="nofollow" target="_blank" href="#"><img style="position: relative; top: 4px; left: 50%;" src="/www-static/assets/images/ajax-loader.gif"></a>');
},
success: function(data) {
$('#ajax-pull-yahoo').hide().fadeIn(3000).html(data);
}
});
// FACEBOOK
var facebook =
{
uid: '<?php echo $user['uid']; ?>',
facebook: '<?php echo $user['facebook']; ?>'
};
$.ajax({
type: "POST", // Using the POST method
url: "/ajax/social/pull/facebook", // The file to call
data: facebook, // Our data to pass
beforeSend: function(){
$('#ajax-pull-twitter').html('<a rel="nofollow" target="_blank" href="#"><img style="position: relative; top: 4px; left: 50%;" src="/www-static/assets/images/ajax-loader.gif"></a>');
},
success: function(data) {
$('#ajax-pull-facebook').hide().fadeIn(3000).html(data);
}
});
正如你所看到的,我做了三發AJAX的帖子,然後不知何故,我得到的結果。
我認爲它的工作原理是這樣的:
it calls ajax twitter
it calls ajax yahoo
it calls ajax facebook
* loading *
lets say yahoo load first
it loads result yahoo on $('#ajax-pull-yahoo')
twitter load second
it loads result twitter on $('#ajax-pull-twitter')
then facebook last.
it loads result twitter on $('#ajax-pull-twitter')
或
it calls ajax twitter
*loading and wait*
it loads result twitter on $('#ajax-pull-twitter')
it calls ajax yahoo
*loading and wait*
it loads result yahoo on $('#ajax-pull-yahoo')
it calls ajax facebook
*loading and wait*
it loads result facebook on $('#ajax-pull-facebook')
如果是第一個那麼它的好。如果它在第二個,我怎麼能使它像第一個?
這只是一個評論,不相關的問題,但你定義了'var twitter = ...'兩次,一次在'// TWITTER'下並且在'// YAHOO'下再次定義# – 2011-05-15 15:08:55
@majid修復了我真正的代碼謝謝!是的,我愛了stackoverflow – 2011-05-15 15:17:34