ajax中文乱码

原因:AJAX接受数据时服务器默认是采用UTF-8的编码形式进行传送,所以在很多GB2312中文网页中应用AJAX回传数据经常会发生中文乱码。

网上搜索了下解决方法有很多,
1、escape unescape
2、服务器端文件加个header,指明送出的是什么编码流

个人喜欢,html编码utf-8,
<meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″ />

服务器端header设定utf-8

header(‘Content-Type:text/xml;charset=utf-8′);

(php)file get contents无法正常使用

一、

有些主机服务商把php的allow_url_fopen选项是关闭了,就是没法直接使用file_get_contents来获取远程web页面的内容。那就是可以使用另外一个函数curl。

下面是file_get_contents和curl两个函数同样功能的不同写法

file_get_contents函数的使用示例:

< ?php
$file_contents = file_get_contents(‘http://www.ccvita.com/’);
echo $file_contents;
?>

换成curl函数的使用示例:

< ?php
$ch = curl_init();
$timeout = 5;
curl_setopt ($ch, CURLOPT_URL, ‘http://www.ccvita.com’);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$file_contents = curl_exec($ch);
curl_close($ch);
echo $file_contents;
?>

Continue Reading

js注释会引起ie6出错?

js是页面外部引用,页面放在zbxe的外部页面,结果ie7,8,火狐均可正常运行,而ie6出错。找了半天,居然是js代码里的注释导致的。

jquery拼图,draggable插件

发现draggale定了axis ,移动太快还是会漂,不知道是不是我代码问题.
对js还是不够熟,虽然看得多,写起来就是感觉不一样。编的过程中,错误很多,思路上可能也有问题。
draggale后面用不好,就能用animate方法了。
demo

 

———————————-
<!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>jquery拼图</title>
<script language=”javascript” src=”jquery.ui/jquery-1.2.4a.js”></script>
<script language=”javascript” src=”jquery.ui/ui.base.min.js”></script>
<script language=”javascript” src=”jquery.ui/ui.draggable.min.js”></script>
<script language=”javascript”>

var x     //取得白方块div的left值
var y     
var sleft = new Array();   //1到8,每个div的移动前的left值
var sstop = new Array();     //1到8,每个div的移动前的top值

$(function(){  
start();
function start(){

for(var i=1;i<9;i++){
x=$(“#f9″).position().left;
y=$(“#f9″).position().top;
sleft[i] = $(“div”).eq(i).position().left

var posx = sleft[i]-x;                             //取得第i个div与白方块#f9的left差值 ,有正负
var absposx = Math.abs(posx);                   //取得第i个div与白方块#f9的left差值的绝对值
sstop[i] = $(“div”).eq(i).position().top

var posy = sstop[i] -y;
var absposy = Math.abs(posy);

if(absposx==200 && absposy == 0){             //判断该移动的轴,x或y轴,并调用stop函数
$(“div”).eq(i).draggable(“enable”);
$(“div”).eq(i).draggable({axis:”x”,containment:”parent”,opacity:0.6,cursor:”move”,snap: true});
$(“div”).eq(i).bind(‘dragstop’, function(event, ui) {     //绑定draggable的stop函数
var index=$(“div”).index(this);
var eleft = $(this).position().left; //取出该div的最终left值,赋值给eleft                   
$(this).animate({left:x,opacity:”0.6″},function(){
x=sleft[index];                        //x的值已经改变
$(this).css(“opacity”,”1″);
$(“#f9″).css(“left”,x);
$(“div”).draggable(“disable”);
$(“div”).unbind(‘dragstop’);           //取消监听事件,重要★★★
start();
});
});
}

else if(absposx==0 && absposy==200){         //y坐标移动
$(“div”).eq(i).draggable(“enable”);
$(“div”).eq(i).draggable({axis:”y”,containment:”parent”,opacity:0.6,cursor:”move”,snap: true });
$(“div”).eq(i).bind(‘dragstop’, function(event, ui){
var index=$(“div”).index(this);                     //i不能作为参数传入该函数,所以定义个index表示序号
var etop = $(this).position().top;            //移动后的top值

$(this).animate({top:y,opacity:”0.6″},function(){
y=sstop[index]
$(this).css(“opacity”,”1″);
$(“#f9″).css(“top”,y);
$(“div”).draggable(“disable”);
$(“div”).unbind(‘dragstop’);
start();
});
});
}
}  
}

});
</script>
<style>

h1{ … Continue Reading

手痒,想写个小游戏,真是不容易啊。。

手痒,想用js+jq写个小游戏,真是不容易啊。。

ie6热区问题

在一个DIV里面插入图片,为什么给这个图片定义了热区后,在IE6里面会把这个div的高度撑高,有什么好的解决办法呢?

解决方法:
img{display:block;}

jquery简单选项卡 slideDown() slideUp()方法

在火狐3.5.3下的效果,加了CSS3 圆角
demo地址

$(function(){                      //jq代码不够精
$("#tab1").click(function(){
$("#d1").removeClass();
$("#d1").addClass("tab0");            //注意:addClass()方法只是添加,而不是替换!
$("#d2").removeClass();
$("#d2").addClass("tab");
$(".content1").slideDown(500);   // 第一个内容框下降
$(".content2").slideUp(500);    //第二个内容框上升*/
/*$(".content1").show();
$(".content2").hide();*/
} );

$("#tab2").click(function(){
$("#d1").removeClass();
$("#d1").addClass("tab");
$("#d2").removeClass();
$("#d2").addClass("tab0");
$(".content1").slideUp(500);   //第一个内容框上升
$(".content2").slideDown(500);  //第二个内容框*/
/*   $(".content2").show();
$(".content1").hide();*/
} );

});

 

body{ background:#CCCCCC;}
.tab,.tab0{
width:80px;
height:30px;
float:left;
margin:2px 2px 0px 2px;
text-align:center;
line-height:30px;
color:#FFFF99;
font-size:12px;
-moz-border-radius-topleft: 5px;
-moz-border-radius-topright: 5px;
}
.tab{background:#333333;}
.tab0{ background:#FFFFFF;}
.clear{ clear:both;}
.content1,.content2{  width:250px;
font-size:12px;
line-height:20px;
margin:0px 2px 2px 2px;
background:#FFFFFF;
/*border:#FFFFFF solid 1px;*/
padding:5px;
-moz-border-radius-bottomleft: 5px;
-moz-border-radius-bottomright: 5px;}
.content2{ display:none;}
a{ text-decoration:none; color:#999999;}

 

<div id="d1" class="tab0"><a id="tab1" href="#">Dota</a></div>
<div id="d2" class="tab"><a id="tab2" href="#">真三</a></div>
<div … Continue Reading

Page 5 of 512345