0

The Twitter code is below:

<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="https://platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script>

This code is on the page comments.php and that gets loaded into social.php when you first load it.
The twitter button works fine at this point.

However, when I post a comment and comments.php reloads but social.php does not reload, the Twitter script does not work and the tweet button doesn't appear.

Please may someone help me. Sorry if I am unclear in any way.

user2166538
  • 313
  • 1
  • 3
  • 18

2 Answers2

0

Generally, javascript is only interpreted after it is loaded. Modifications after the initial interpretation via ajax won't be interpreted.

jQuery .load() call doesn't execute javascript in loaded html file

might be related, check it out...

Community
  • 1
  • 1
Mr.Manhattan
  • 5,315
  • 3
  • 22
  • 34
0

Ok, so you should load your Twitter widget outside comments.php because the script won't be loaded via Ajax.

That would be easier to manage and will avoid your Twitter widget to be loaded each time. There is no need to call this script for an external source (Twitter) for each post, this is no efficient and error-prone.

By doing this that will fix you problem.

glautrou
  • 3,140
  • 2
  • 29
  • 34
  • So there is a mistake in your code, add the widget to social.php (which is not reloaded). There is no reason that shouldn't work. – glautrou Aug 26 '13 at 12:28
  • i also reload two jquery codes along with the twitter code in comments.php, both the jquery codes work – user2166538 Aug 26 '13 at 12:31
  • What about the widget? – glautrou Aug 26 '13 at 12:32
  • i have found the problem, the script for twitter does not include a $(document).ready(function(){ therefore it doesn't work, however the google plus button does and it works fine – user2166538 Aug 26 '13 at 15:19
  • im accepting the answer to get rep, but this was not the solution. i needed an ascyronous version of the loading script – user2166538 Aug 26 '13 at 19:26