依扬博客 Blog For Business and IT Technology
41312634's Blog, thoughts, activities, news, studies, travels, movies, cates and so on included.
首页   留言簿  订阅更新  投稿专区 
Ajax的一般使用方法
分类: JavaScript    2008-05-27 00:00:44    浏览 546    评论 0   

初始化Ajax对象后就可以在程序中随时使用,

function show_province_city(pid)
{   
    if(!request)
    {
        alert("Error initializing XMLHttpRequest!");
    }
    else
    {
        var url = "listcity.php?province_id=" + pid;
        request.open("GET", url, true);
        request.onreadystatechange = function ()
                                    {
                                        if (request.readyState == 4)
                                        {
                                            if (request.status == 200)
                                            {
                                                var responseContent = request.responseText;
                                                document.getElementById("city_list").innerHTML = responseContent;
                                            }
                                            else
                                            {
                                                alert("status is " + request.status);
                                            }
                                        }
                                    };
        request.send(null);
    }
}

request.onreadystatechange = 的应该是一个函数名,为了简便,直接对其定义一个操作函数,JS对这种做法是支持的。

上一篇:初始化Ajax对象的操作
下一篇:PHP生成汉字图片的问题

相关文章
[2008-05-26 23:54:40]  JavaScript计算md5的函数 (636/0)
[2008-05-26 23:56:29]  JavaScript控制元素显示还是隐藏的函数 (601/0)
[2008-05-26 23:58:15]  初始化Ajax对象的操作 (562/0)
[2008-05-30 01:42:39]  JavaScript获取域名 (621/0)
[2008-05-30 01:46:40]  JavaScript元素切换图片 (545/0)
[2008-05-30 02:21:58]  JavaScript字符串替换函数 (562/0)
[2008-06-01 01:25:25]  JavaScript判断是否安装有Alexa工具条 (613/0)
[2008-07-03 14:52:54]  JavaScript让页脚保持在底部 (564/0)
[2008-07-03 17:37:01]  JavaScript获取当前滚动位置 (598/0)
[2008-10-05 15:05:28]  网站项目的多语种解决方案概述 (589/0)

本文评论列表 (0)

发表评论
姓名(*)
链接地址
Email
验证码(*) 更换验证码
评论(*) (管理员审核后公开显示)