jquery ajax获取后台传过来的值 总结



设置字符集编码:
 contentType: "application/json;utf-8",








1,html处理比较简单,直接输出即可
一般用${"jb51div"}.innerHTML等即可




2,json格式数据的调用
$.ajax({ 
url : "/trundle/RawContentAction.getAjaxContent.act", 
data : "param1=22", 
dataType : "json",//这里的dataType就是返回回来的数据格式了html,xml,json 
cache: false,//设置是否缓存,默认设置成为true,当需要每次刷新都需要执行数据库操作的话,需要设置成为false 
success : function(data) { 
$(data).each(function(te, u) { 
alert(te); 
$("#content").append(u.title+"
"); 
}) 

}) 
3,xml格式数据调用
$.ajax({ 
url : "/trundle/RawContentAction.getAjaxContent.act", 
data : "param1=22", 
dataType : "xml",//这里的dataType就是返回回来的数据格式了html,xml,json 
cache: false,//设置是否缓存,默认设置成为true,当需要每次刷新都需要执行数据库操作的话,需要设置成为false 
success : function(xml) { 
$(xml).find("*").each(function(){ 
//这边对遍历出来的内容进行处理,jquery都是可以使用xpath进行遍历的 
}) 

}) 
---------------------------------------------
$(function() {
            $("#Button1").click(function() { //按钮单击事件
                //打开文件,并通过回调函数处理获取的数据
                $.get("UserInfo.xml", function(data) {
                    $("#divTip").empty(); //先清空标记中的内容
                    var strHTML = ""; //初始化保存内容变量
                    $(data).find("User").each(function() { //遍历获取的数据
                        var $strUser = $(this);
                        strHTML += "姓名:" + $strUser.find("name").text() + "
";
                        strHTML += "性别:" + $strUser.find("sex").text() + "
";
                        strHTML += "邮箱:" + $strUser.find("email").text() + "
";
                    })
                    $("#divTip").html(strHTML); //显示处理后的数据
                })
            })








4,遍历数组,list


  
***************************************************************************
 
====================================================
遍历数组


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

你可能感兴趣的:(jquery ajax获取后台传过来的值 总结)