Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Regular Coder
    Join Date
    Oct 2007
    Posts
    277
    Thanks
    2
    Thanked 4 Times in 4 Posts

    Exclamation HELP - Script not working...

    here is the script:
    Code:
    <script language="javascript" type="text/javascript">
    <!-- 
    //Browser Support Code
    window.onload=function ajaxFunction(){
    	var ajaxRequest;  // The variable that makes Ajax possible!
    	
    	try{
    		// Opera 8.0+, Firefox, Safari
    		ajaxRequest = new XMLHttpRequest();
    	} catch (e){
    		// Internet Explorer Browsers
    		try{
    			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
    		} catch (e) {
    			try{
    				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
    			} catch (e){
    				// Something went wrong
    				alert("Your browser broke!");
    				return false;
    			}
    		}
    	}
    	// Create a function that will receive data sent from the server
    	requestNews = ajaxRequest;
    	requestNews.onreadystatechange = function(){
    		if(requestNews.readyState == 4){
    			var newsDisplay = document.getElementById("news");
    			newsDisplay.innerHTML = requestNews.responseText;
    		}
    	}
    	requestNews.open("GET", "news.php", true);
    	requestNews.send(null); 
    }
    //-->
    </script>
    here is the page:
    Code:
    <!-- here is the header style of the page-->
    <center>
    <div style="border:1px solid black;background-color:#DDDD00;width:95%;padding:2px;" align="right">
    .ברוכים הבאים לניאוסטאר, כאן תוכלו למצוא את כל העזרה שאתם צריכים בניאופטס
    </div>
    <br>
    <table cellspacing="5" cellpadding="0" width="95%">
    <thead style="background-color:#DDDD00;">
    <tr>
    <td align="right" style="font-size:15pt;font-weight:bold;font-family:arial;">:חדשות</td>
    </tr>
    </thead>
    <tbody id="news">
    
    </tbody>
    </table>
    </center>
    <!-- here is the footer style of the page-->
    here is the php:
    PHP Code:
    <?php
    //here includes the config
    // how many rows to show per page
    $rowsPerPage 5;

    // by default we show first page
    $pageNum 1;

    $query  "SELECT * FROM news LIMIT 5";
    $result mysql_query($query) or die('Error:4;');

    // print the random numbers
    while($row mysql_fetch_array($result))
    {
    echo 
    '<tr>';
    echo 
    '<td>';
    echo 
    '<table cellspacing="0" align="center" width="100%">';
    echo 
    '<tbody align="right" style="background-color:white;">';
    echo 
    '<tr>';
    echo 
    '<td>';
    echo 
    $row['text'];
    echo 
    '  </td>';
    echo 
    '</tr>';
    echo 
    '</tbody>';
    echo 
    '<tfoot style="background-color:#DDDD00;">';
    echo 
    '<tr>';
    echo 
    '<td colspan="5" align="right">'.$row['date'].'</td>';
    echo 
    '</tr>';
    echo 
    '</tfoot>';
    echo 
    '</table>';
    echo 
    '</td>';
    echo 
    '</tr>';
    }

    ?>
    the problem is that it doesn't put the response text in the table body with the id news
    Last edited by shedokan; 11-14-2007 at 11:53 AM.

  • #2
    Senior Coder shyam's Avatar
    Join Date
    Jul 2005
    Posts
    1,563
    Thanks
    2
    Thanked 163 Times in 160 Posts
    whats not working? exactly
    You never have to change anything you got up in the middle of the night to write. -- Saul Bellow

  • #3
    Regular Coder
    Join Date
    Oct 2007
    Posts
    277
    Thanks
    2
    Thanked 4 Times in 4 Posts
    oh yea, forgot.
    the problem is that it doesn't put the response text in the table body with the id news.
    Last edited by shedokan; 11-14-2007 at 11:55 AM.

  • #4
    Senior Coder shyam's Avatar
    Join Date
    Jul 2005
    Posts
    1,563
    Thanks
    2
    Thanked 163 Times in 160 Posts
    did u check if the news.php is returning any results by putting its url in a browser?
    You never have to change anything you got up in the middle of the night to write. -- Saul Bellow

  • #5
    Regular Coder
    Join Date
    Oct 2007
    Posts
    277
    Thanks
    2
    Thanked 4 Times in 4 Posts
    yes here's a link to news.php:
    http://neostar.110mb.com/news.php
    and here's a link to the page:
    http://neostar.110mb.com/test.php

  • #6
    Regular Coder
    Join Date
    Oct 2007
    Posts
    277
    Thanks
    2
    Thanked 4 Times in 4 Posts
    now here's where I am:
    the script is working only in firefox and not in IE.
    here is the new ajax script:
    Code:
    <script language="javascript" type="text/javascript">
    <!-- 
    //Browser Support Code
    function createXMLHttpRequest(){
    	var ajaxRequest;  // The variable that makes Ajax possible!
    	
    	try{
    		// Opera 8.0+, Firefox, Safari
    		ajaxRequest = new XMLHttpRequest();
    	} catch (e){
    		// Internet Explorer Browsers
    		try{
    			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
    		} catch (e) {
    			try{
    				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
    			} catch (e){
    				// Something went wrong
    				alert("Your browser broke!");
    				return false;
    			}
    		}
    	}
    return ajaxRequest;
    }
    function callback(id){ 
    	if (xmlHttp.readyState==4){ 
    		if(xmlHttp.status==200){
    			document.getElementById(id).innerHTML=xmlHttp.responseText;
    		}else{
    			document.getElementById(id).innerHTML="Cannot find page: " + xmlHttp.status;
    		}
    	}else{
    		document.getElementById(id).innerHTML="Waiting for server...";
    	}
    }
    function ajaxFunction(){
    	// Create a function that will receive data sent from the server
    	var newsDisplay = document.getElementById("news");
    		document.getElementById("news").innerHTML="Starting...";
    		xmlHttp=createXMLHttpRequest();
    		xmlHttp.onreadystatechange=function(){callback("news")};
    		xmlHttp.open("GET", "news.php'.$page.'", true);
    		xmlHttp.send(null); 
    }
    window.onload=function(){ajaxFunction()};
    //-->
    </script>


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •