首页 > 编程技术 > php

ajax+php 无刷新数据调用经典实例

发布时间:2016-11-25 16:29

<!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>ajax+php 无刷新数据调用经典实例</title>
<script>
function G(id){
  return document.getElementById(id);
 }
 
 function createXMLHttpRequest(){//创建XMLHttpRequest对象
  if(window.ActiveXObject){//IE
    try {
     return new ActiveXObject("Microsoft.XMLHTTP");
    } catch(e){
     return;
    }
   }else if(window.XMLHttpRequest){//Mozilla,firefox
    try {
     return new XMLHttpRequest();
    } catch(e){
     return;
    }
   }
  }

 function returnCity(Value,divId,at,pid){//主调函数
  var xmlHttp=createXMLHttpRequest();
  var url = "s.php?cid="+Value+"&at="+at+"&pid="+pid+"&mt="+Math.random(100);
  //alert(url);
  if (Value==""){  
   return false ;
  }
  if (xmlHttp){
   callback = getReadyStateHandler(xmlHttp,divId);
   xmlHttp.onreadystatechange = callback;
   xmlHttp.open("GET", url,true);
   xmlHttp.send(null);
  }
 }

 function getReadyStateHandler(xmlHttp,divId){//服务器返回后处理函数
  return function (){
   if(xmlHttp.readyState == 4){
    if(xmlHttp.status == 200){        
      if (xmlHttp.responseText){
       G(divId).innerHTML=xmlHttp.responseText;     
      }else{
       G(divId).innerHTML="";     
      }      
    }
   }
  }
 }
 
 function ajaxData(inputName,divId,action,cpid)
 {
  //alert(inputName);
  var cityid = G(inputName).value;
  var pid = G(cpid).value;  
  returnCity(cityid,divId,action,pid);

 }
</script>
</head>

<body>
<input name="" type="text" onMouseOver="ajaxData('city_type','cityareaid','c','borough_type');" />
<div id="ajaxHtml">
</div>
</body>
</html>
//s.php文件
$Db = new Db();
  $type = ( $action=='esfPice')?1:2;  
  $sql = "Select * from cn_loupan_city_price where city_id ='$cid' and price_type='$type'";
  $query = $Db->query( $sql );
  $str ='';
  if( $Db->rows( $query ) )
  {
   $result = $Db->fetch( $query ,0);
   foreach( $result as $_v => $v )
   {
    
    $str .= "<LI><A onClick="switchprop('price2_Value','".$v['city_price_show']."','price2_List','price','".$v['city_price']."')" href="javascript教程:void(0);" target=_self>".$v['city_price_show']."</A></LI>";    
   }
   echo $str;
  }
  else
  {
   exit('可不选!');
  }  
  //这里只讲ajax不讲数据库教程连接
www.111cn.net原他

<?php教程 

002 $file_path = './download/download_cn.rar'; 

003   

004 //使用方法 

005 downFile($file_path); 

006   

007 // 服务器文件路径,下载文件名字(默认为服务器文件名),是否许可用户下载方式(默认可选),速度限制(默认自动),文件类型(默认所有) 

008 function downFile($fileName, $fancyName = '', $forceDownload = true, $speedLimit = 0, $contentType = '') {  

009     if (!is_readable($fileName))  

010     {  

011         header("HTTP/1.1 404 Not Found");  

012         return false;  

013     }  

014     

015     $fileStat = stat($fileName);  

016     $lastModified = $fileStat['mtime'];  

017     

018     $md5 = md5($fileStat['mtime'] .'='. $fileStat['ino'] .'='. $fileStat['size']);  

019     $etag = '"' . $md5 . '-' . crc32($md5) . '"';  

020     

021     header('Last-Modified: ' . gmdate("D, d M Y H:i:s", $lastModified) . ' GMT');  

022     header("ETag: $etag");  

023     

024     if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) >= $lastModified)  

025     {  

026         header("HTTP/1.1 304 Not Modified");  

027         return true;  

028     }  

029     

030     if (isset($_SERVER['HTTP_IF_UNMODIFIED_SINCE']) && strtotime($_SERVER['HTTP_IF_UNMODIFIED_SINCE']) < $lastModified)  

031     {  

032         header("HTTP/1.1 304 Not Modified");  

033         return true;  

034     }  

035     

036     if (isset($_SERVER['HTTP_IF_NONE_MATCH']) &&  $_SERVER['HTTP_IF_NONE_MATCH'] == $etag)  

037     {  

038         header("HTTP/1.1 304 Not Modified");  

039         return true;  

040     }  

041     

042     if ($fancyName == '')  

043     {  

044         $fancyName = basename($fileName);  

045     }  

046     

047     if ($contentType == '')  

048     {  

049         $contentType = 'application/octet-stream';  

050     }  

051     

052     $fileSize = $fileStat['size'];  

053     

054     $contentLength = $fileSize;  

055     $isPartial = false;  

056     

057     if (isset($_SERVER['HTTP_RANGE']))  

058     {  

059         if (preg_match('/^bytes=(d*)-(d*)$/', $_SERVER['HTTP_RANGE'], $matches))  

060         {  

061             $startPos = $matches[1];  

062             $endPos = $matches[2];  

063     

064             if ($startPos == '' && $endPos == '')  

065             {  

066                 return false;  

067             }  

068     

069             if ($startPos == '')  

070             {  

071                 $startPos = $fileSize - $endPos;  

072                 $endPos = $fileSize - 1;  

073             }  

074             else if ($endPos == '')  

075             {  

076                 $endPos = $fileSize - 1;  

077             }  

078     

079             $startPos = $startPos < 0 ? 0 : $startPos;  

080             $endPos = $endPos > $fileSize - 1 ? $fileSize - 1 : $endPos;  

081     

082             $length = $endPos - $startPos + 1;  

083     

084             if ($length < 0)  

085             {  

086                 return false;  

087             }  

088     

089             $contentLength = $length;  

090             $isPartial = true;  

091         }  

092     }  

093     

094     // send headers  

095     if ($isPartial)  

096     {  

097         header('HTTP/1.1 206 Partial Content');  

098         header("Content-Range: bytes $startPos-$endPos/$fileSize");  

099     

100     }  

101     else 

102     {  

103         header("HTTP/1.1 200 OK");  

104         $startPos = 0;  

105         $endPos = $contentLength - 1;  

106     }  

107     

108     header('Pragma: cache');  

109     header('Cache-Control: public, must-revalidate, max-age=0');  

110     header('Accept-Ranges: bytes');  

111     header('Content-type: ' . $contentType);  

112     header('Content-Length: ' . $contentLength);  

113     

114     if ($forceDownload)  

115     {  

116         header('Content-Disposition: attachment; filename="' . rawurlencode($fancyName). '"');  

117     }  

118     

119     header("Content-Transfer-Encoding: binary");  

120     

121     $bufferSize = 2048;  

122     

123     if ($speedLimit != 0)  

124     {  

125         $packetTime = floor($bufferSize * 1000000 / $speedLimit);  

126     }  

127     

128     $bytesSent = 0;  

129     $fp = fopen($fileName, "rb");  

130     fseek($fp, $startPos);  

131     while ($bytesSent < $contentLength && !feof($fp) && connection_status() == 0 )  

132     {  

133         if ($speedLimit != 0)  

134         {  

135             list($usec, $sec) = explode(" ", microtime());  

136             $outputTimeStart = ((float)$usec + (float)$sec);  

137         }  

138     

139         $readBufferSize = $contentLength - $bytesSent < $bufferSize ? $contentLength - $bytesSent : $bufferSize;  

140         $buffer = fread($fp, $readBufferSize);  

141     

142         echo $buffer;  

143     

144         ob_flush();  

145         flush();  

146     

147         $bytesSent += $readBufferSize;  

148     

149         if ($speedLimit != 0)  

150         {  

151             list($usec, $sec) = explode(" ", microtime());  

152             $outputTimeEnd = ((float)$usec + (float)$sec);  

153     

154             $useTime = ((float) $outputTimeEnd - (float) $outputTimeStart) * 1000000;  

155             $sleepTime = round($packetTime - $useTime);  

156             if ($sleepTime > 0)  

157             {  

158                 usleep($sleepTime);  

159             }  

160         }  

161     }  

162     return true;  

163 }  

164 ?>

$path ="d:pdoSpiderResult.db3";
 $conn = new PDO("sqlite:$path");
 $array=array('','',''); 

 if( $conn )
 {
  //echo ('connection pdo success');
 }
 else
 {
  echo ('cnnection pdo fail ,plase check database server!');
 }
 $count=0;
 $sp = new SplitWord();
 foreach ($conn->query('SELECT * FROM content limit 160,80') as $row)
 {
  
  // baise info
  
  $softtitle = mysql教程_escape_string(mb_convert_encoding($row[3],'gbk','auto')).'-js相册';//title
  
  //file title
  
  $softcontent =  str_replace('Image/','http://g.111cn.net/javascript教程/Image/',mb_convert_encoding($row

[4],'gbk','auto'));
  
  //file size of size
  
  $softsize = '未知';
  
  // file downurl
  
  $softurl = str_replace('.zip','',$row['address']);
  $filetype='.rar';
  $softpath='http://g.111cn.net/javascript/'.$softurl.$filetype;
  $view ='<br />效果预览地址<a href=http://g.111cn.net/javascript/'.$softurl.'

target=_blank>'.$softtitle.'</a>';//效果预览地址

      preg_match_all("/(src|SRC)=["|'| ]{0,}((.*).(gif|jpg|jpeg|png|bmp))/isU",$softcontent,$img_array);
  $thum = str_replace("'",'',str_replace('"','',$img_array[2][0]));
  $softlinks = mysql_escape_string("{dede:link islocal='1' text='$localhost'}".$softpath."{/dede:link}");
  $a = strip_tags($softcontent);
  $b = $sp->SplitRMM($softtitle);
  $keywords = str_replace(' ',',',$b);
  
  $desciption = '';//desc + split word
  $introduce =$softcontent.$desciption.$view;
  $os ='Win2003,WinXP,Win2000,Win9X';
  //call out link  descript 
   
  $addsoft = "Insert into d_addonsoft(typeid,filetype,language,softtype,accredit,

os,softrank,officialUrl,officialDemo,softsize,softlinks,introduce,templet,userip,redirecturl)";
   $addsoft .=" values

('$typeid','$filetype','$language','','','$os','3','','','$softsize','".$softlinks."','$introduce','','222.103.69.94','')";

   mysql_query( $addsoft ) or die('addsoft'.$addsoft.mysql_error());//.$addsoft
   $newid = mysql_insert_id();
  
   // Read insert new id
          
   $sortrank = time();
  
   //Read the minutes and seconds when the system is currently
  
   $click = mt_rand(1000,10000);
  
   // Random Clicks 1000 , 10000 btween   
  
  
   $archives = "Insert into d_archives

(id,typeid,typeid2,sortrank,flag,ismake,channel,arcrank,click,money,title,litpic,writer,source,pubdate,senddate,mid,descripti

on,keywords)";  
   $archives.=" values

('$newid','$typeid','0','$sortrank','p','1','3','0','$click','0','$softtitle','$thum','$write','unkown','$sortrank','$sortran

k',1,'$desciption','$keywords')";
  
   mysql_query($archives) or die('archives '.$archives.'|'.mysql_error()); //$archives.
   $arctiny = "Insert into d_arctiny(id,typeid,typeid2,arcrank,channel,senddate,sortrank,mid) values

($newid,$typeid,0,0,3,'$sortrank','$sortrank',1)";
  
   mysql_query( $arctiny) or die( 'arctiny'.$arctiny.mysql_error());//$arctiny.
 
 }
 echo '总共有多条',$count,"不存地的";

本站原创转载注明来源www.111cn.net

<?php
//fsocket模拟post提交
$purl = "http://localhost/netphp/test2.php?uu=rrrrrrrrrrrr";
print_r(parse_url($url));
sock_post($purl,"uu=55555555555555555");

//fsocket模拟get提交
function sock_get($url, $query)
{
   $info = parse_url($url);
   $fp = fsockopen($info["host"], 80, $errno, $errstr, 3);
   $head = "GET ".$info['path']."?".$info["query"]." HTTP/1.0 ";
   $head .= "Host: ".$info['host']." ";
   $head .= " ";
   $write = fputs($fp, $head);
   while (!feof($fp))
   {
    $line = fread($fp,4096);
    echo $line;
   }
}
sock_post($purl,"uu=rrrrrrrrrrrrrrrr");

function sock_post($url, $query)
{
   $info = parse_url($url);
   $fp = fsockopen($info["host"], 80, $errno, $errstr, 3);
   $head = "POST ".$info['path']."?".$info["query"]." HTTP/1.0 ";
   $head .= "Host: ".$info['host']." ";
   $head .= "Referer: http://".$info['host'].$info['path']." ";
   $head .= "Content-type: application/x-www-form-urlencoded ";
   $head .= "Content-Length: ".strlen(trim($query))." ";
   $head .= " ";
   $head .= trim($query);
   $write = fputs($fp, $head);
   while (!feof($fp))
   {
    $line = fread($fp,4096);
    echo $line;
   }
}

?>

php教程 中文与英语正则表达式
<!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>php 中文与英语正则表达式</title>
</head>

<body>
<form id="111cnNet" name="111cnNet" method="post" action="">

<input name="url" type="text"  />
<input name="" type="submit"   value="提交 "/>
</form>

</body>
</html>
<?
function funcChinese($str,$num1='',$num2='')//判断中文正则
 {
  if($num1!='' and $num2!=''){
   return (preg_match("/^([x81-xfe][x40-xfe])

{".$num1.",".$num2."}$/",$str))?true:false;
  }else{
   return (!eregi("[^x80-xff]","$str"))?

true:false;
  }
 }

if( $_POST)
{
 if( funcChinese( $_POST['url'] )  )
 {
  echo '是中文';
 }
 else
 {
  exit('不是有效中文');
 }
}
//这个只能一个个字符判断哦,你可以用foreach来处理
?>

标签:[!--infotagslink--]

您可能感兴趣的文章: