将PHP变量传递到多个<;span>;使用Javascript的标记
我一直在四处寻找一个类似的问题,但我找不到。 我正试图将twitter/facebook/rss关注者的数量推到侧边栏中的将PHP变量传递到多个<;span>;使用Javascript的标记,php,jquery,html,Php,Jquery,Html,我一直在四处寻找一个类似的问题,但我找不到。 我正试图将twitter/facebook/rss关注者的数量推到侧边栏中的… 为了得到这些数字,我使用了一些php脚本。在一个单独的文件中,我有javascript,在我的sidebar.php文件中,我有…。 我试着调试一切,但找不到我的错误 在侧边栏中,我使用: <div id="social-bar"> <ul> <li c
…
为了得到这些数字,我使用了一些php脚本。在一个单独的文件中,我有javascript,在我的sidebar.php文件中,我有…
。
我试着调试一切,但找不到我的错误
在侧边栏中,我使用:
<div id="social-bar">
<ul>
<li class="rss-count"><a href="http://feeds.feedburner.com/dewereldverzamelaar"><span>..........</span></a></li>
<li class="twitter-count"><a href="http://twitter.com/deverzamelaar"><span>..........</span></a></li>
<li class="facebook-count"><a href="http://www.facebook.com/dewereldverzamelaar"><span>..........</span></a></li>
</ul>
<!--END #social-bar-->
</div>
我知道php脚本可以工作,因为它们响应了正确数量的追随者。我认为jQuery也可以工作,因为计数器达到3,div社交栏就会出现。但它不会显示追随者的数量,它会一直显示。
我不是php/html或jQuery专家。我抓取了一些片段,并试图构建一些内容。
为什么回音没有传到
?我希望有人能解释和帮助我
问候
乔纳斯·斯梅茨
这里是编辑过的版本,记住它已经在“jQuery(document).ready(function(){)”中了,因为还有很多其他脚本(来自wordpress主题)正在加载:
var count, loadCallback;
count = 0;
loadCallback = function(response, status, request) {
// Since you use the same code in all the callbacks, you might as well
// only declare the function once. Since we're doing that, we might as
// well merge tz_showSocial into here as well...
if (request.status != 200) {
alert('Oh no! Something went wrong with the update! (HTTP '+request.status+')');
}
count++;
if (count > 2) {
jQuery('#social-bar').fadeIn(200);
}
};
// As Dvir Azulay correctly points out, you should execute the AJAX calls
// in the ready event
jQuery('.rss-count span').load('/includes/update-rss.php', loadCallback);
jQuery('.twitter-count span').load('/includes/update-twitter.php', loadCallback);
jQuery('.facebook-count span').load('/includes/update-facebook.php', loadCallback);
有了这个版本的代码,肯定会发生一些事情:
页面加载正常,但变为空白?这与jQuery脚本有关,如果我取出脚本,页面加载正常
如果你需要任何额外的信息,请告诉我。
乔纳斯·斯梅茨
//////////////////////////////////////////////////
仍然不起作用,这是我现在拥有的:
/* here are some variables I've added for my script: */
var count, loadCallback;
count = 0;
/*-----------------------------------------------------------------------------------
Custom JS - All front-end jQuery
-----------------------------------------------------------------------------------*/
/*-----------------------------------------------------------------------------------*/
/* Remove JavaScript fallback class
/*-----------------------------------------------------------------------------------*/
jQuery('#container').removeClass('js-disabled');
/*-----------------------------------------------------------------------------------*/
/* Let's get ready!
/*-----------------------------------------------------------------------------------*/
jQuery(document).ready(function() {
/* here you get some other scripts the theme uses */
/* here my script start */
loadCallback = function(response, status, request) {
// Since you use the same code in all the callbacks, you might as well
// only declare the function once. Since we're doing that, we might as
// well merge tz_showSocial into here as well...
if (request.status != 200) {
alert('Oh no! Something went wrong with the update! (HTTP '+request.status+')');
}
count++;
if (count > 2) {
jQuery('#social-bar').fadeIn(200);
}
};
// As Dvir Azulay correctly points out, you should execute the AJAX calls
// in the ready event
jQuery('.rss-count span').load('http://developer.dewereldverzamelaar.net/wp-content/themes/gridlocked/includes/update-rss.php', loadCallback);
jQuery('.twitter-count span').load('http://developer.dewereldverzamelaar.net/wp-content/themes/gridlocked/includes/update-twitter.php', loadCallback);
jQuery('.facebook-count span').load('http://developer.dewereldverzamelaar.net/wp-content/themes/gridlocked/includes/update-facebook.php', loadCallback);
/* again one other script the theme uses */
/* at the end this script closes the document.ready function closes */
现在页面仍然会重新加载到空白页面。当我取出jQuery代码时,一切又恢复正常了。我不知道该怎么做才能让它正常工作
乔纳斯
Oke,出于某种原因,它现在可以工作了。不知道我做了什么更改。对于有相同问题的人,这是有效的jQuery代码,我没有更改我的php和html代码,它们从一开始就很好:
/* Some Variables outside the document.ready function */
var count, loadCallback;
count = 0;
/*-----------------------------------------------------------------------------------*/
/* Let's get ready!
/*-----------------------------------------------------------------------------------*/
jQuery(document).ready(function() {
/*-----------------------------------------------------------------------------------*/
/* Social Count Script
/*-----------------------------------------------------------------------------------*/
loadCallback = function(response, status, request) {
// Since you use the same code in all the callbacks, you might as well
// only declare the function once. Since we're doing that, we might as
// well merge tz_showSocial into here as well...
if (request.status != 200) {
alert('Oh no! Something went wrong with the update! (HTTP '+request.status+')');
}
count++;
if (count > 2) {
jQuery('#social-bar').fadeIn(200);
}
};
// As Dvir Azulay correctly points out, you should execute the AJAX calls
// in the ready event
jQuery('.rss-count span').load('http://developer.dewereldverzamelaar.net/wp-content/themes/gridlocked/includes/update-feedburner.php', loadCallback);
jQuery('.twitter-count span').load('http://developer.dewereldverzamelaar.net/wp-content/themes/gridlocked/includes/update-twitter.php', loadCallback);
jQuery('.facebook-count span').load('http://developer.dewereldverzamelaar.net/wp-content/themes/gridlocked/includes/update-facebook.php', loadCallback);
/* Some other scripts go here, at the end the document.ready function is closed. */
谢谢。
Jonas Smets在我看来好像是在DOM完全加载之前执行jQuery代码,这可能包括侧栏
尝试将所有jQuery代码放在
$(document).ready(function(){jQuery code});
块中。在我看来,您好像是在DOM完全加载之前执行jQuery代码,这可能包括侧栏
尝试将所有jQuery代码放在$(document).ready(function(){jQuery code});
块中
www.deweredverzamelaar.com
提供?因为如果不是,它绝对不会工作,因为var count, loadCallback;
count = 0;
loadCallback = function(response, status, request) {
// Since you use the same code in all the callbacks, you might as well
// only declare the function once. Since we're doing that, we might as
// well merge tz_showSocial into here as well...
if (request.status != 200) {
alert('Oh no! Something went wrong with the update! (HTTP '+request.status+')');
}
count++;
if (count > 2) {
jQuery('#social-bar').fadeIn(200);
}
};
// As Dvir Azulay correctly points out, you should execute the AJAX calls
// in the ready event
$(document).ready(function() {
$('.rss-count span').load('http://www.dewereldverzamelaar.com/wp-content/developer/themes/gridlocked/includes/update-rss.php', loadCallback);
$('.twitter-count span').load('http://www.dewereldverzamelaar.com/wp-content/developer/themes/gridlocked/includes/update-twitter.php', loadCallback);
$('.facebook-count span').load('http://www.dewereldverzamelaar.com/wp-content/developer/themes/gridlocked/includes/update-facebook.php', loadCallback);
});
www.deweredverzamelaar.com
提供?因为如果不是,它绝对不会工作,因为var count, loadCallback;
count = 0;
loadCallback = function(response, status, request) {
// Since you use the same code in all the callbacks, you might as well
// only declare the function once. Since we're doing that, we might as
// well merge tz_showSocial into here as well...
if (request.status != 200) {
alert('Oh no! Something went wrong with the update! (HTTP '+request.status+')');
}
count++;
if (count > 2) {
jQuery('#social-bar').fadeIn(200);
}
};
// As Dvir Azulay correctly points out, you should execute the AJAX calls
// in the ready event
$(document).ready(function() {
$('.rss-count span').load('http://www.dewereldverzamelaar.com/wp-content/developer/themes/gridlocked/includes/update-rss.php', loadCallback);
$('.twitter-count span').load('http://www.dewereldverzamelaar.com/wp-content/developer/themes/gridlocked/includes/update-twitter.php', loadCallback);
$('.facebook-count span').load('http://www.dewereldverzamelaar.com/wp-content/developer/themes/gridlocked/includes/update-facebook.php', loadCallback);
});
你在哪里用php回显结果?为什么不直接回显到相应的
s中?在XML上使用regex是死刑的理由。因此:p你在这里用php回显结果?为什么不直接回显到相应的
s中?在XML上使用regex是死刑的理由所以:PHi伙计们,非常感谢您的回复。我不知道任何同源策略。我正在开发一个名为的子域。脚本在同一台服务器上。这可能是问题吗?我编写的jQuery脚本已经在jQuery(document).ready(function(){和许多其他脚本中(这是我的wordpress主题的一部分,所以我没有写它们)所以这不是问题。DaveRandom,如果你的脚本没有在文档中准备好,它会是什么样子?我已经编辑了指向php文件的链接,所以我没有使用绝对链接,因为这给了我一个“哦,不,出了什么事”的句子。现在我不明白这个句子。页面开始加载,我可以看到我的内容,但不能重新加载它进入了一个白色页面?这里可能有什么问题?Jonas@JonasSmets如果你用你的新代码编辑问题,我会很高兴地看一看-很难在注释中阅读代码…嘿,戴夫,对不起,我是新来的堆栈溢出。我已经更新了我的第一篇文章。目前,我不确定为什么页面会重新加载一个空白页面(这意味着document.write(“”);
正在被调用,或者某个地方发生了重定向),但是您应该将所有代码从ajax调用中移开(jQuery('.rss count span')。load(…);
等等)在.ready
函数之外。这是因为您需要创建的对象存在于比.ready
函数更高级别的作用域中,因为HTTP请求是a-同步的…如果您想对此进行进一步解释,请询问,我将尽我最大的努力…嗨,伙计们,非常感谢您的回复。我不知道这方面的任何情况起源策略。我正在开发一个名为。脚本的子域。脚本在同一台服务器上。这可能是问题吗?我编写的jQuery脚本已经存在于jQuery(document).ready(function(){以及许多其他脚本(它们是我的wordpress主题的一部分,所以我没有编写它们)所以这不是问题。DaveRandom,如果你的脚本没有在文档中准备好,它会是什么样子?我已经编辑了php文件的链接,因此
var count, loadCallback;
count = 0;
loadCallback = function(response, status, request) {
// Since you use the same code in all the callbacks, you might as well
// only declare the function once. Since we're doing that, we might as
// well merge tz_showSocial into here as well...
if (request.status != 200) {
alert('Oh no! Something went wrong with the update! (HTTP '+request.status+')');
}
count++;
if (count > 2) {
jQuery('#social-bar').fadeIn(200);
}
};
// As Dvir Azulay correctly points out, you should execute the AJAX calls
// in the ready event
$(document).ready(function() {
$('.rss-count span').load('http://www.dewereldverzamelaar.com/wp-content/developer/themes/gridlocked/includes/update-rss.php', loadCallback);
$('.twitter-count span').load('http://www.dewereldverzamelaar.com/wp-content/developer/themes/gridlocked/includes/update-twitter.php', loadCallback);
$('.facebook-count span').load('http://www.dewereldverzamelaar.com/wp-content/developer/themes/gridlocked/includes/update-facebook.php', loadCallback);
});