文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>jQuery学习笔记——ajax

jQuery学习笔记——ajax

时间:2010-07-17  来源:mataocn

<div class="letter" id="letter-a">
        <h3>
                <a href="#">A</a>
        </h3>
</div>
<div id="dictionary">
</div>

 

$(document).ready(function () {
        $("#letter-a a").click(function () {
                $.get("jqueryGet", {"term":$(this).attr('href')}, function (data) {
                        $("#dictionary").html(data);
                });
                alert("test");
                return false;
        });
});

 

public class JqueryGet extends HttpServlet {

        public void doPost(HttpServletRequest request, HttpServletResponse response)
                        throws ServletException, IOException {
                System.out.println("POST");
                System.out.println(request.getParameter("term"));
                
                // 返回值为字符串类型,相应的head设置为text/html
                response.setContentType("text/html;charset=UTF-8");

                PrintWriter out = response.getWriter();

                out.write("<h3 class=\"term\">ABDICATION</h3>");
        }

        // Process the HTTP Get request
        public void doGet(HttpServletRequest request, HttpServletResponse response)
                        throws ServletException, IOException {
                System.out.println("GET");
                doPost(request, response);
        }

}

 

说明:

1、$.get方法的第一个参数是链接后台的URL

2、$.get方法的第二个参数是传递给后台的Parameter

3、$(this)是点击的对象,$(this).attr(‘href’)的值是’#’,$(this).text()的值是’A’

4、$.get方法的第三个参数是回调函数,参数data可以是字符串,也可以是dom对象或者json对象

5、$(“#dictionary”).html(data)相当于setHTML

6、$(“#dictionary”).html()相当于getHTML

7、alert(“test”)可能会先于回调函数执行,这就是异步调用

8、return false是为了防止单击这些链接时打开新的URL,因此在事件处理程序中必须返回false

 

相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载