2 lrlthink Lrlthink 于 2013.11.28 11:11 提问

ajax异步查询结果的显示?

function querySubmit(){
$.ajax({
type: "get",
url: "/personinfomanage/queryDatas",
data:{"name":$("#searchName").val(),"skill":$("#searchSkill").val()},
dataType: "json",
success:function (result) {
alert("success!");
if(result!=""){
var datalist = eval ("(" + result + ")");
alert(datalist);
var cur=1;
createPages(totalpage,cur);//生成页码
var persons = data.persons;
var i;
for(i = 0;i<persons.length;i++){

         }
        }
    }
});

为什么function(result)不执行? 用firebug执行到function(result)语句就跳出了?
json设置方式:
PrintWriter out = null;
response.setContentType("application/json");
try {
out = response.getWriter();
out.write(result);
} catch (IOException e) {
e.printStackTrace();
}
System.out.println(result);

下面是我的json字符串:System.out.println(result);的结果

[{"id":766,"description":"what the fuck?!","creationTime":"2013-11-07","firstName":"Michael","lastName":"Gyger","skills":"","birthDate":"0001-01-01","email":"counter55@yahoo.com","webSiteName":"NONE","genderTag":1,"birthYear":1,"phone":"","photo":"","interests":"","certification":""},{"id":768,"description":"CISA,CISM,CISSP,MCSE","creationTime":"2013-11-07","firstName":"Michael","lastName":"Gerleman","skills":"","birthDate":"0001-01-01","email":"michael_gerleman@yahoo.com","webSiteName":"MGerleman","genderTag":1,"birthYear":1,"phone":"","photo":"","interests":"","certification":""},{"id":769,"description":"","creationTime":"2013-11-07","firstName":"Michael","lastName":"Palamar","skills":"","birthDate":"0001-01-01","email":"map0009@aol.com","webSiteName":"MichaelPalamar","genderTag":1,"birthYear":1,"phone":"","photo":"","interests":"","certification":""},{"id":799,"description":"","creationTime":"2013-11-07","firstName":"Michael","lastName":"Roth","skills":"","birthDate":"0001-01-01","email":"MJRoth@hot.rr.com","webSiteName":"NONE","genderTag":1,"birthYear":1,"phone":"","photo":"","interests":"","certification":""},{"id":821,"description":"","creationTime":"2013-11-07","firstName":"Michael","lastName":"Story","skills":"","birthDate":"0001-01-01","email":"mutineer7@hotmail.com","webSiteName":"NONE","genderTag":1,"birthYear":1,"phone":"","photo":"","interests":"","certification":""}]

1个回答

whk010
whk010   2013.11.28 13:53

输出的格式错误,应该是一个串,不应该是多个串,修改成一个就可以了。{"id":"821"...,"id":"822"...},希望你能看懂我的写法

Lrlthink
Lrlthink 是一个串啊 只是太长了,这就自动换行了。我验证了json的格式是对的,而且我生成json是用objectMapper自动生成的。
大约 4 年之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!