AJAX jquery

jquery~~~ajax get方法实例,英汉词典,数据抓取百度字典。

----------------------------------------------------------
----------------------------------------------------------

index.php
------------------------------

<style type="text/css">
body,th,td{font-size:14px;}
</style>
<script language="javascript" src="jquery.js"></script>
<script language="javascript">
$(document).ready(function(){
    $("#dicsearch").click(function(){
   $.ajax({ url: "get.php",
              type:"get",           
              dataType:"html",
              data: "type=dic&zhi="+document.getElementById('dicinput').value,
              success:function(msg){
              $("#showdic").html(msg);
              }});
       });
});
</script>
<div id="dicbody">
<div id="dics" style="float:left">英汉词典:
   <input name="dicinput" type="text" maxlength="20" /><input name="dicsearch" type="submit" id="dicsearch" value="查询" /></div>
<div id="showdic" style="float:left"></div>
</div>
--------------------------------------------------
get.php
--------------------------------------------------
<?
Header("Content-type: text/html;charset=GB2312");
function curl($url) {
$ch=curl_init($url);
$fp=fopen("temp.txt","a");
curl_setopt($ch,CURLOPT_FILE,$fp);
curl_setopt($ch,CURLOPT_HEADER,0);
fwrite($fp,curl_exec($ch));
curl_close($ch);
fclose($fp);
$content=file_get_contents("temp.txt");
unlink("temp.txt");
return $content;
}
$type=$_GET[type];
$zhi=$_GET[zhi];
if ($type=="dic") {
$content=curl("http://www.baidu.com/baidu?ie=gb2312&ct=1048576&cl=3&word=".$zhi);
preg_match("/(?<=<ol/>).*?(?=<//ol/>)/is",$content,$dic);
$text=str_replace("IMAGES","http://www.baidu.com/IMAGES",$dic[0]);
echo $text;
}
?>

 

==================================================================================

<script language="javascript" src="Scripts/jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
        getInfo();  
        // 每隔一定时间和服务器交互一次  
        setInterval(getInfo,10000);  
});  
//从服务器获取数据的方法  
function getInfo(){  
   $.ajax({ url: "userShout.php",
            type:"get",          
            dataType:"html",
            data: "",
            success:function(msg){ //回调方法 显示返回信息到 DIV:newsmsg
             $("#newsmsg").html(msg);
            }}); 
}  
</script>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值