473,385 Members | 1,343 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

ajax help please

77
The following code is giving no output on my site. its supposed to show user veiws on the index page. can anyone find anything wrong with it?

http://herproom.5.forumer.com/index.php?

Expand|Select|Wrap|Line Numbers
  1.  
  2. <script type="text/javascript">
  3. <!--
  4. /*
  5. Users Viewing In Main Page Board Cells
  6. Coded By Greg/Moose
  7. Don't repost or edit
  8. */
  9. var addrequest;
  10. var viewadds = new Array();
  11. var curnum = 0;
  12. var td = document.getElementsByTagName('td');
  13. for(t=0;t<td.length;t++){
  14. if(td[t].getElementsByTagName('a')[0] && td[t].getElementsByTagName('a')[0].href.match(/showforum=\d+/)){
  15. viewadds.push(td[t]);
  16. }}
  17. checkBViews();
  18. function checkBViews(){
  19. if(window.ActiveXObject){
  20. addrequest = new ActiveXObject("Microsoft.XMLHTTP");
  21. } else {
  22. addrequest = new XMLHttpRequest();
  23. }
  24. var opener = viewadds[curnum].getElementsByTagName('a')[0].href;
  25. addrequest.onreadystatechange = function(){
  26. addBViews();
  27. }
  28. addrequest.open("GET",opener,true);
  29. addrequest.send('');
  30. }
  31. function addBViews(){
  32. if(addrequest.readyState == 4 && addrequest.status == 200){
  33. var resptext = addrequest.responseText;
  34. var addiv = document.createElement('div');
  35. addiv.innerHTML = resptext;
  36. var hdiv = addiv.getElementsByTagName('div');
  37. var views = 0;
  38. for(a=0;a<hdiv.length;a++){
  39. if(hdiv[a].className == "darkrow2" && hdiv[a].innerHTML.match(/^(\d+) User\(s\) are browsing this forum/)){
  40. views = parseInt(RegExp.$1) - 1;
  41. }}
  42. if(views < 0){
  43. views = 0;
  44. }
  45. if(views != 0){
  46. var viewstext = document.createTextNode( ' ('+views+' viewing'+')');
  47. viewadds[curnum].insertBefore(viewstext,viewadds[curnum].getElementsByTagName('br')[0]);
  48. }
  49. curnum++;
  50. if(curnum != viewadds.length){
  51. checkBViews();
  52. } else {
  53. termViews();
  54. }}}
  55. function termViews(){
  56. if(window.ActiveXObject){
  57. addrequest = new ActiveXObject("Microsoft.XMLHTTP");
  58. } else {
  59. addrequest = new XMLHttpRequest();
  60. }
  61. addrequest.open("GET",location.href,true);
  62. addrequest.send('');
  63. }
  64. //-->
  65. </script>
  66.  
Nov 19 '07 #1
23 1891
acoder
16,027 Expert Mod 8TB
Do you have any errors?

For the send method, use send(null) instead of an empty string.
Nov 19 '07 #2
Inny
77
I changed the send to send(null) but still no output. I think my variables are wrong, instead of 'veiws' my site has '{ibf.lang.h_hits}'
not sure how to rewrite it without ruining the code?

Expand|Select|Wrap|Line Numbers
  1. <th width='7%' align='center' nowrap="nowrap" class='titlemedium'>{ibf.lang.h_hits}</th>
Nov 22 '07 #3
acoder
16,027 Expert Mod 8TB
So do you get any errors? Check the JavaScript console.
Nov 22 '07 #4
Inny
77
yes I got 2 errors following (couldnt cut n paste)



Nov 22 '07 #5
acoder
16,027 Expert Mod 8TB
Which lines are these?

Line 732 is obviously part of the Ajax code that you've already posted.
Nov 22 '07 #6
Inny
77
Yes it is, as for the other im not sure without posting the entire source to see where the line comes up, not sure how to make stuff display like the code above?
Nov 22 '07 #7
Inny
77
I expect the other error is not to do with it. I dont know where I can test it and get correct line numbers
Nov 22 '07 #8
acoder
16,027 Expert Mod 8TB
When do you run this code?

Is it run during page load? If so, the tables, etc. may not be loaded yet. This should be executed after page load.
Nov 22 '07 #9
Inny
77
When do you run this code?

Is it run during page load? If so, the tables, etc. may not be loaded yet. This should be executed after page load.
how would I make it run After page load? /defer?
Nov 23 '07 #10
Inny
77
how would I make it run After page load? /defer?
I tried

<script defer src="http://h1.ripway.com/Inny/showem.js" type="text/javascript"></script>

where 'showem' is the code above (even though its only IE supported) but nothing.
Nov 23 '07 #11
acoder
16,027 Expert Mod 8TB
how would I make it run After page load? /defer?
Put it in a function and call it on body onload or window.onload.
Nov 23 '07 #12
Inny
77
Put it in a function and call it on body onload or window.onload.
Errr...I have no idea how to do that! Putting the function in my onload I can do, but whats the actual Function?
Nov 23 '07 #13
Inny
77
This is what The ajax code above is designed to work around. (note: I dont have access to these php files) Maybe this will help sombody create a succesful code for me?

Expand|Select|Wrap|Line Numbers
  1. Mod Name:   Amount of Users showed on board
  2. Author:     x00179
  3. AuthorMail: x00179@hotmail.com
  4. Author HP:  www.dorg4u.com/x00179
  5. IPB Ver:    1.3pr2 
  6. Decs.
  7. this will show how many people are in a specific category and forum? 
  8.  
  9. Open sources\boards.php
  10. Find
  11.     var $children = array();
  12. Add Below
  13.     var $UsOnBo      = array();
  14.  
  15. Find
  16.     // Get the forums and category info from the DB
  17. Add below
  18.     if ($ibforums->vars['au_cutoff'] == "")    $ibforums->vars['au_cutoff'] = 15;
  19.     $time    = time() - ($ibforums->vars['au_cutoff'] * 60);        
  20.         $DB->query("SELECT COUNT(*) as mcnt,in_forum FROM ibf_sessions WHERE running_time > '$time' GROUP BY in_forum");
  21.         while ( $r = $DB->fetch_row() ) $this->UbOnBo[$r['in_forum']] = $r['mcnt'];
  22. Find
  23.         if ($forum_data['subwrap'] == 1)
  24.         {
  25. Add Above
  26.         $count_users=0;    
  27.  
  28. Find
  29.                         $newest['last_poster_name'] = $data['last_poster_name'];
  30.                         $newest['status']           = $data['status'];
  31.                     }
  32. Add Below
  33.                     //users are where?
  34.                     $count_users += $this->UbOnBo[$newest['fid']];
  35.  
  36.  
  37. Find
  38.                 return $this->html->ForumRow($forum_data);
  39.  
  40.             }
  41.             else
  42. Add above
  43.                 //users are where?
  44.                 if($count_users) {$forum_data['description'] .= "<span class='highlight'> (".$count_users.")</span>";}
  45. Find
  46.             $forum_data['posts']  = $std->do_number_format($forum_data['posts']);
  47.             $forum_data['topics'] = $std->do_number_format($forum_data['topics']);
  48. Add Below
  49.             $count_users += $this->UbOnBo[$forum_data['id']];
  50.             if($count_users) {$forum_data['description'] .= "<span class='highlight'> (".$count_users.")</span>";}
  51. Close & Save
  52. Open Board\Forums.php
  53. Find
  54.         $DB->query("SELECT f.*, m.member_name as mod_name, m.member_id as mod_id, m.is_group, m.group_id, m.group_name, m.mid
  55. Add Above
  56.     //Users are where ?
  57.         $UbOnBo = array();
  58.         if ($ibforums->vars['au_cutoff'] == "")    $ibforums->vars['au_cutoff'] = 15;
  59.         $DB->query("SELECT COUNT(s.id) as mcnt,s.in_forum 
  60.                     FROM ibf_forums as f
  61.                     LEFT JOIN ibf_sessions as s ON (s.in_forum=f.parent_id AND s.running_time > '$time') 
  62.                     WHERE f.parent_id='$fid'
  63.                     GROUP BY s.in_forum");
  64.         while ( $r = $DB->fetch_row() ) $UbOnBo[$r['in_forum']] = $r['mcnt'];
  65. Find
  66.         while ( $r = $DB->fetch_row() )
  67.         {
  68. Replace with
  69.         $count_users = 0;
  70.         while ( $r = $DB->fetch_row() )
  71.         {
  72.             $count_users = $UbOnBo[$r['id']];
  73.             if($count_users) {$r['description'] = $r['description']."<span class='highlight'> (".$count_users.")</span>";}
  74. Find
  75.         $total_topics_printed = 0;
  76.  
  77.         if ( ($ibforums->vars['show_user_posted'] == 1) and ($ibforums->member['id']) )
  78. Add Above
  79.         // User are where
  80.         $UbOnBo = array();
  81.         if ($ibforums->vars['au_cutoff'] == "")    $ibforums->vars['au_cutoff'] = 15;
  82.         $DB->query("SELECT COUNT(*) as mcnt,in_topic 
  83.                     FROM ibf_sessions WHERE in_forum='{$this->forum['id']}'
  84.                     GROUP BY in_topic");
  85.         while ( $r = $DB->fetch_row() ) $UbOnBo[$r['in_topic']] = $r['mcnt'];            
  86.  
  87.  
  88. Find
  89.         while ( $topic = $DB->fetch_row() )
  90.         {
  91. Replace with
  92.         $count_users=0;
  93.         while ( $topic = $DB->fetch_row() )
  94.         {
  95.             //users are where?
  96.             $count_users = $UbOnBo[$topic['tid']];
  97.                 if($count_users) {$topic['description'] .="<span class='highlight'> (".$count_users.")</span>";}
  98. Close & Save
  99.  
  100.  
  101.  
  102.  
  103.  
  104.  
Nov 25 '07 #14
acoder
16,027 Expert Mod 8TB
Errr...I have no idea how to do that! Putting the function in my onload I can do, but whats the actual Function?
In the code in post #1, lines 8-16 are not inside the function which means they will execute whilst the page is loading.

Put these statements inside a function, e.g. function init() {...} and then call this onload.
Nov 26 '07 #15
Inny
77
like this?

Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2. <!--
  3. /*
  4. Users Viewing In Main Page Board Cells
  5. Coded By Greg/Moose
  6. Don't repost or edit
  7. */
  8.  
  9. function init() {
  10.  
  11. var addrequest;
  12. var viewadds = new Array();
  13. var curnum = 0;
  14. var td = document.getElementsByTagName('td');
  15. for(t=0;t<td.length;t++){
  16. if(td[t].getElementsByTagName('a')[0] && td[t].getElementsByTagName('a')[0].href.match(/showforum=\d+/)){
  17. viewadds.push(td[t]);
  18. }}
  19. checkBViews();
  20. }
  21.  
  22. function checkBViews(){
  23. if(window.ActiveXObject){
  24. addrequest = new ActiveXObject("Microsoft.XMLHTTP");
  25. } else {
  26. addrequest = new XMLHttpRequest();
  27. }
  28. var opener = viewadds[curnum].getElementsByTagName('a')[0].href;
  29. addrequest.onreadystatechange = function(){
  30. addBViews();
  31. }
  32. addrequest.open("GET",opener,true);
  33. addrequest.send('');
  34. }
  35. function addBViews(){
  36. if(addrequest.readyState == 4 && addrequest.status == 200){
  37. var resptext = addrequest.responseText;
  38. var addiv = document.createElement('div');
  39. addiv.innerHTML = resptext;
  40. var hdiv = addiv.getElementsByTagName('div');
  41. var views = 0;
  42. for(a=0;a<hdiv.length;a++){
  43. if(hdiv[a].className == "darkrow2" && hdiv[a].innerHTML.match(/^(\d+) User\(s\) are browsing this forum/)){
  44. views = parseInt(RegExp.$1) - 1;
  45. }}
  46. if(views < 0){
  47. views = 0;
  48. }
  49. if(views != 0){
  50. var viewstext = document.createTextNode( ' ('+views+' viewing'+')');
  51. viewadds[curnum].insertBefore(viewstext,viewadds[curnum].getElementsByTagName('br')[0]);
  52. }
  53. curnum++;
  54. if(curnum != viewadds.length){
  55. checkBViews();
  56. } else {
  57. termViews();
  58. }}}
  59. function termViews(){
  60. if(window.ActiveXObject){
  61. addrequest = new ActiveXObject("Microsoft.XMLHTTP");
  62. } else {
  63. addrequest = new XMLHttpRequest();
  64. }
  65. addrequest.open("GET",location.href,true);
  66. addrequest.send('');
  67. }
  68. //-->
  69. </script>
  70. <body onload='init();'>
Nov 26 '07 #16
acoder
16,027 Expert Mod 8TB
like this?
Actually, on second thoughts, no, but almost. Put the first three lines outside init() because they are global variables which are used in other functions.
Nov 26 '07 #17
Inny
77
It still dosent work, no output on the index
Nov 26 '07 #18
acoder
16,027 Expert Mod 8TB
Do you get any errors?
Nov 27 '07 #19
Inny
77
No errors But no output. maybe You know An Ajax Expert who could help?
Dec 8 '07 #20
Inny
77
Got this working but It wont Work In IE. How To Make It Work In IE?

Also, The Second Code Below kills it, How to re-write that one so its in harmony?

Expand|Select|Wrap|Line Numbers
  1.  
  2. <script type="text/javascript">
  3. <!--
  4. /*
  5. Users Viewing In Main Page Board Cells
  6. Coded By Greg/Moose
  7. */
  8. var addrequest;
  9. var viewadds = new Array();
  10. var curnum = 0;
  11. var td = document.getElementsByTagName('td');
  12. for(t=0;t<td.length;t++){
  13. if(td[t].getElementsByTagName('a')[0] && td[t].getElementsByTagName('a')[0].href.match(/showforum=\d+/)){
  14. viewadds.push(td[t]);
  15. }}
  16. checkBViews();
  17. function checkBViews(){
  18. if(window.ActiveXObject){
  19. addrequest = new ActiveXObject("Microsoft.XMLHTTP");
  20. } else {
  21. addrequest = new XMLHttpRequest();
  22. }
  23. var opener = viewadds[curnum].getElementsByTagName('a')[0].href;
  24. addrequest.onreadystatechange = function(){
  25. addBViews();
  26. }
  27. addrequest.open("GET",opener,true);
  28. addrequest.send('');
  29. }
  30. function addBViews(){
  31. if(addrequest.readyState == 4 && addrequest.status == 200){
  32. var resptext = addrequest.responseText;
  33. var addiv = document.createElement('div');
  34. addiv.innerHTML = resptext;
  35. var hdiv = addiv.getElementsByTagName('div');
  36. var views = 0;
  37. for(a=0;a<hdiv.length;a++){
  38. if(hdiv[a].className == "darkrow2" && hdiv[a].innerHTML.match(/^(\d+) User\(s\) are browsing this forum/)){
  39. views = parseInt(RegExp.$1) - 1;
  40. }}
  41. if(views < 0){
  42. views = 0;
  43. }
  44. if(views != 0){
  45. var viewstext = document.createTextNode( ' ('+views+' viewing'+')');
  46. viewadds[curnum].insertBefore(viewstext,viewadds[curnum].getElementsByTagName('br')[0]);
  47. }
  48. curnum++;
  49. if(curnum != viewadds.length){
  50. checkBViews();
  51. } else {
  52. termViews();
  53. }}}
  54. function termViews(){
  55. if(window.ActiveXObject){
  56. addrequest = new ActiveXObject("Microsoft.XMLHTTP");
  57. } else {
  58. addrequest = new XMLHttpRequest();
  59. }
  60. addrequest.open("GET",location.href,true);
  61. addrequest.send('');
  62. }
  63. //-->
  64. </script>
Expand|Select|Wrap|Line Numbers
  1. <script type='text/javascript'>
  2. <!--
  3. function ResizeThem(){
  4. maxheight=200;
  5. maxwidth= 200;
  6. imgs=document.getElementsByTagName("img");
  7. for (p=0; p<imgs.length; p++) {
  8. if (imgs[p].getAttribute("alt")=="user posted image") {
  9. w=parseInt(imgs[p].width);
  10. h=parseInt(imgs[p].height);
  11. if (parseInt(imgs[p].width)>maxwidth) {
  12. imgs[p].style.cursor="pointer";
  13. imgs[p].onclick=new Function("iw=window.open(this.src,'ImageViewer','resizable=1');iw.focus()");
  14. imgs[p].height=(maxwidth/imgs[p].width)*imgs[p].height;
  15. imgs[p].width=maxwidth;}
  16. if (parseInt(imgs[p].height)>maxheight) {
  17. imgs[p].style.cursor="pointer";
  18. imgs[p].onclick=new
  19. Function("iw=window.open(this.src,'ImageViewer','resizable=1');iw.focus()");
  20. imgs[p].width=(maxheight/imgs[p].height)*imgs[p].width;
  21. imgs[p].height=maxheight;}}}}
  22. ResizeThem()
  23. //-->
  24. </script>
Dec 9 '07 #21
acoder
16,027 Expert Mod 8TB
Got this working but It wont Work In IE. How To Make It Work In IE?
Do you get any errors? What happens in IE?
Dec 10 '07 #22
Inny
77
Seems to Working Now but the image resizer code above kills it on firefox!

Go figure!
Dec 10 '07 #23
acoder
16,027 Expert Mod 8TB
Seems to Working Now but the image resizer code above kills it on firefox!
Any errors or just not working?
Dec 11 '07 #24

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Larry | last post by:
I am wondering if anyone has any thoughts on the following issues once Ajax is incorporated into a page: Now that we have this Ajax stuff, users have the potential to not leave a page for a long...
6
by: =?Utf-8?B?SmFrb2IgTGl0aG5lcg==?= | last post by:
I have a solution with four webprojects developed in Visual Studio 2003. It is upgraded to Visual Studio Team System 2005 / Framework 2.0. Now I tried to AJAX enable one of the web projects. ...
4
by: =?Utf-8?B?R2VyaGFyZA==?= | last post by:
I am just stating to use ajax, and have a perfect place to use the accordion control. I have it working fine, but need to have a normal asp button in one of the panes that fires an onclick event...
8
by: jd2007 | last post by:
Why the Ajax code below in ajax.js is causing my form not to work ? ajax.js: var a=0; var b=0; var c=0; var d=0; var e=0; var f=0;
2
by: shivendravikramsingh | last post by:
hi friends, i m using a ajax function for retrieving some values from a database table,and display the values in required field,my prob is that the ajax function i m using is working f9 once,but if...
9
by: Trapulo | last post by:
Hello, with ASP.NET 2.0 Ajax every unexpected error is managed client-side with a popup that reports the error to the user. In ASP.NET 3.5 this behavor has been changed: how can I have a similar...
1
by: Mark B | last post by:
This is my first try at using AJAX. I want the calendars to be enabled if the user checks CheckBox1. It works OK for a normal all page refresh but once I introduced the AJAX code it stopped...
7
by: =?Utf-8?B?QmlsbHkgWmhhbmc=?= | last post by:
我们现在遇到一个问题,通过wcf创建的webservice,选择windows service作为宿主,采用java作为客户端调用成功,但是无法使用asp.net ajax调用。...
11
by: =?Utf-8?B?R2VyaGFyZA==?= | last post by:
I have run into a situation that if a page/tab that uses the Ajax toolkit (using .net version 3.5) is closed before the Ajax enable controls complete loading, then IE locks up. Does it in both IE7...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.