Need help with ajax display problem in FF

Discussion in 'PHP' started by mgrohan, Jul 12, 2008.

  1. #1
    I am using the below code for a whois. It currently works fine in ie but it is not working in FF.

    Any help appreciated.

    <?php 
    error_reporting(7);
    set_time_limit(300);
    
    // Server List File
    $config['server_list'] = "servers.lst";
    
    $domain = trim($_POST['domain']);
    $domain = strtolower($domain);
    
    if(substr($domain,0,7) == "http://") {
    	$domain = str_replace("http://","",$domain);
    }
    if(substr($domain,0,4) == "www.") {
    	$domain = str_replace("www.","",$domain);
    }
    
    function whois_request($server, $query)
    {
        $data = "";
    	if(!$fp = @fsockopen($server, 43)) {
    		Return false;
    	} else {
    		fputs($fp, $query . "\r\n");
            while (!feof($fp)) {
                $data .= fread($fp, 1000);
            } 
            fclose($fp);
    	}
        return nl2br($data);
    }
    
    function get_server() {
    	global $config,$domain;
    	$serverarray = file($config['server_list']);
    	$i = 0;
    	foreach($serverarray as $key=>$val) {
    		if(substr($val,0,1) != "#") {
    			$server_p = explode("|",$val);
    			$server[$i]['tld'] = $server_p[0];
    			$server[$i]['server'] = $server_p[1];
    			$server[$i]['avail'] = $server_p[2];
    			$server[$i]['infoserver'] = $server_p[3];
    			$server[$i]['backserver'] = $server_p[4];
    			$server[$i]['info'] = $server_p[5];
    		}
    		$i++;
    	}
    
    	$domain_c = explode(".",$domain);
    	$partnum = count($domain_c);
    	$last_part_1 = $domain_c[$partnum-1];
    	$last_part_2 = $domain_c[$partnum-2];
    	
    	foreach($server as $key=>$val) {
    		if($val['tld'] == $last_part_2.".".$last_part_1) {
    			Return $val;
    		} elseif($val['tld'] == $last_part_1) {
    			Return $val;
    		}
    	}
    	Return false;
    }
    
    function startwhois() {
    	global $domain;
    	if(!$server = get_server()) {
    		die("无法查询此类型的域名");
    	}
    	$result1 = whois_request($server['server'], $domain);
    	$result2 = whois_request($server['infoserver'], $domain);
    	if(!$result1 && !$result2) {
    		echo "无法连接服务器";
    		die();
    	} else {
    		$result = $result1."<br />".$result2;
    		echo $result;
    	}
    }
    
    if(isset($_GET['action']) && trim($_GET['action']) == "do") {
    	startwhois();
    	die();
    }
    ?> 
    
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title>Whois</title>
    <link href="../images/global.css" rel="stylesheet" type="text/css" />
    <script src="../images/global.js" type="text/javascript"></script>
    <SCRIPT type="text/javascript">
    <!--
    	var xmlHttp;
    	function creatXMLHttpRequest() {
    		if(window.ActiveXObject) {
    			xmlHttp = new ActiveXObject('Microsoft.XMLHTTP');
    		} else if(window.XMLHttpRequest) {
    			xmlHttp = new XMLHttpRequest();
    		}
    	}
    
    	function startRequest() {
    		var queryString;
    		var domain = document.getElementById('domain').value;
    		queryString = "domain=" + domain;
    		creatXMLHttpRequest();
    		xmlHttp.open("POST","?action=do","true");
    		xmlHttp.onreadystatechange = handleStateChange;
    		xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded;");
    		xmlHttp.send(queryString);
    	}
    
    	function handleStateChange() {
    		if(xmlHttp.readyState == 1) {
    			document.getElementById('result').style.cssText = "";
    			document.getElementById('result').innerText = "Loading...";
    		}
    		if(xmlHttp.readyState == 4) {
    			if(xmlHttp.status == 200) {
    				document.getElementById('result').style.cssText = "";
    				var allcon =  xmlHttp.responseText;
    				document.getElementById('result').innerHTML = allcon;
    			}
    		}
    	}
     
    //-->
    </SCRIPT>
    </head>
    <body>
    <div style="margin-top:20px; margin-bottom:12px; text-align:center;">
    <div class="t"><a href="http://xn--h6qv61aktwxux.com"><img src="../images/logo.png" alt="Whois" border="0" /></a></div>
    <div class="t f14">
    	<div>
    		<a href="http://xn--h6qv61aktwxux.com">IP/域名</a>&nbsp;&nbsp;
    		<a href="../alexa/">Alexa</a>&nbsp;&nbsp;
    		<a href="../sfz/">身份证</a>&nbsp;&nbsp;
    		<a href="../sj/">手机</a>&nbsp;&nbsp;
    		<a href="../gr/">收录</a>&nbsp;&nbsp;
    		Whois&nbsp;&nbsp;
    		<a href="../yz/">邮编区号</a>
    &nbsp;&nbsp;	</div>
    </div>
    </div>
    <center> 
    <div class="c">
    	<div>
        <input name="domain" type="text" size="36" maxlength="100" id="url"  />
        <input type="button" name="button"  value="Whois" id="sub" onclick="startRequest();" />
    </div>
      <div id="result" style="display:none"></div>
    
    </div>
     
     
      </center>
    
    <img src="images/loading.gif" width="0" height="0" />
    
    <?php include "../footer.php"; ?>
    Code (markup):
     
    mgrohan, Jul 12, 2008 IP
  2. hostrs.com

    hostrs.com Peon

    Messages:
    157
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    What is FF?
     
    hostrs.com, Jul 12, 2008 IP
  3. mgrohan

    mgrohan Active Member

    Messages:
    671
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    58
    #3
    FF=Firefox
     
    mgrohan, Jul 12, 2008 IP
  4. mbreezy

    mbreezy Active Member

    Messages:
    135
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    55
    #4
    You need to be more specific... We dont even know how it's supposed to look. Also, AJAX isn't a PHP function so it should probably go in the webdesign forum.
     
    mbreezy, Jul 12, 2008 IP
  5. mgrohan

    mgrohan Active Member

    Messages:
    671
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    58
    #5
    I'm not sure if it is ajax or php. The code is php so i posted it here.

    The problem is the result:
      <div id="result" style="display:none"></div>
    Code (markup):
    displays fine when searching the whois on internet explorer. on firefox however the result does not display. seeing as i am a coder i do not know more specifics, all code is in one file and that has been posted.
     
    mgrohan, Jul 13, 2008 IP
  6. Danltn

    Danltn Well-Known Member

    Messages:
    679
    Likes Received:
    36
    Best Answers:
    0
    Trophy Points:
    120
    #6
    PHP code is server specific - not browser specific.
    If you're having problems with it only working in one browser, it'll be a JS/HTML issue.

    Dan
     
    Danltn, Jul 13, 2008 IP
  7. mgrohan

    mgrohan Active Member

    Messages:
    671
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    58
    #7
    OK thanks, i will look into that.
     
    mgrohan, Jul 13, 2008 IP
  8. php-lover

    php-lover Active Member

    Messages:
    261
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    58
    #8
    Change your function creatXMLHttpRequest function to the code below. We are going to javascript now. :)

    function creatXMLHttpRequest(){
    
    try {
          xmlHttp = new XMLHttpRequest();     
         
         }catch(e) {
         
           try {
         
                xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");       
         
           } catch (e) {
             
                try {
             
                      xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");          
                
                } catch (e) {
              
                xmlHttp = false;
             
             }//catch 
           
           }//catch
         
         }//catch
         
    }//end function creatXMLHttpRequest
    PHP:
     
    php-lover, Jul 13, 2008 IP