这里是我的一块的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