问题描述
- 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":""}]
解决方案
输出的格式错误,应该是一个串,不应该是多个串,修改成一个就可以了。{"id":"821"...,"id":"822"...},希望你能看懂我的写法