NutzCN Logo
问答 SyntaxError: Unexpected end of JSON input
发布于 2012天前 作者 qq_f69514b1 4619 次浏览 复制 上一个帖子 下一个帖子
标签: gradle

这是前台代码:


I am hello ^_^





<%=request.getAttribute("obj")%>
按钮



$("#btn").click(function(){
Ajax('/GradleNutz/app', '/appinfo', 'GET', true, null, function (data) {
if (data.success) {
alert(data);
console.log(data);
} else {
alert('返回错误'+data);
console.log(data);
}
});
})


这是后台程序:
package demo.hello;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import javax.sql.DataSource;
import org.h2.tools.Server;
import org.nutz.dao.Dao;
import org.nutz.dao.impl.NutDao;
import org.nutz.ioc.impl.NutIoc;
import org.nutz.ioc.loader.json.JsonLoader;
import org.nutz.mvc.annotation.At;
import com.alibaba.druid.pool.DruidDataSourceFactory;
import com.alibaba.fastjson.JSONObject;
import com.xjc.pojo.DssAppInfo;
@At("/app")
public class AppModule {
@At("/appinfo")
public String getAppInfo() {
Response response = new Response();
try {
String port = "9094";
Properties prop = new Properties();
Map<String, DssAppInfo> appMap = new HashMap<String, DssAppInfo>();
Server dbServer = Server.createTcpServer("-tcp", "-tcpPort", port, "-tcpAllowOthers").start();
System.out.println(String.format("H2 Server 在 [ %s ] 上启动成功", dbServer.getURL()));
InputStream is = getClass().getResourceAsStream("jdbc.properties");
prop.load(new InputStreamReader(is));
DataSource dataSource = DruidDataSourceFactory.createDataSource(prop);
Dao dao = new NutDao(dataSource);
DssAppInfo app = dao.fetch(DssAppInfo.class);
appMap.put("app", app);
response.setData(appMap);
response.setSuccess(true);
System.out.println("成功"+response.responseVal());
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
response.setMsg(e.getMessage());
response.setSuccess(false);
System.out.println("失败"+response.responseVal());
}
return response.responseVal();
}
}
一直报错SyntaxError: Unexpected end of JSON input
前台拿不到后台的值

2 回复

用插入代码按钮来贴代码,不然没法看

添加回复
请先登陆
回到顶部