Chinaunix首页 | 论坛 | 博客
  • 博客访问: 353974
  • 博文数量: 42
  • 博客积分: 3970
  • 博客等级: 中校
  • 技术积分: 714
  • 用 户 组: 普通用户
  • 注册时间: 2007-12-13 15:31
文章分类

全部博文(42)

文章存档

2009年(19)

2008年(23)

我的朋友

分类: 系统运维

2009-06-09 01:00:54

    最近开始学jquery和ajax,写了一个最简单的脚本。
1.html
 
 

<script src="jquery.js"></script>

<script>
$().ready(function(){
    $.post('test.php', {
        text: 'my string',
    }, function(responseText) {
        alert(responseText);
    });
});

</script>

 

服务端php程序

test.php

<?
if($_GET['text']=='my string'){
    $responseText = 'aa';
    echo $responseText;
}
else{
    $responseText = 'bb';
    echo $responseText;
}

?>

后来在FF和chrome下都没问题,能正常alert,不过在ie下死活不行,上网查了一下,很多都说是编码的问题,ajex传输都是用utf-8,而ie确实用GB2312,后来我把1.html,test.php和apache上默认编码都改成utf-8还不行,后来我把jquery的ajax的$.post改为$.ajax,前者是后者的post提交的简写,后来IE就没问题,看来$.post对ie兼容不好

修改后的1.html

 

<script>
$().ready(function(){
    $.ajax({
        type: "POST",
        url:"test.php",
        cache:false,
        success:function(responseText){
        alert(responseText);
            
        }
    })
});
</script>

阅读(3906) | 评论(2) | 转发(0) |
给主人留下些什么吧!~~

chinaunix网友2009-12-22 15:59:20

还是错的

chinaunix网友2009-08-15 15:39:21

错错错错错错错错错错错错错错