【发布时间】:2018-12-12 16:05:24
【问题描述】:
我正在尝试将内容加载到以下片段中。当我对 html 模板进行基本映射时,我已确认此片段有效。
<div id="fbtresult" th:if="${not #lists.isEmpty(fbts)}" th:fragment="fbtList">
<h2>Frequent Bought Together List</h2>
<table class="table table-striped">
<tr>
<th>Id</th>
<th>Main Product Id</th>
<th>FBT 1 Product ID </th>
<th>FBT 2 Product ID</th>
<th>BSR</th>
<th>View</th>
</tr>
<tr th:each="fbt : ${fbts}">
<td th:text="${fbt.id}"><a href="/fbt/${fbt.id}">Id</a></td>
<td th:text="${fbt?.mainProduct?.asin}">main product asin</td>
<td th:text="${fbt.sproductFbt1 != null} ? ${fbt.sproductFbt1.asin} : ''">product fbt1 asin</span>
<td th:text="${fbt.sproductFbt2 != null} ? ${fbt.sproductFbt2.asin} : ''">product fbt2 asin</span>
<td th:text="${fbt.bsr}">bsr</td>
<td><a th:href="${ '/fbt/' + fbt.id}">View</a></td>
</tr>
</table>
</div>
但是,我正在尝试使用 canvasjs click 函数中的以下查询加载语句。我已经确认 jquery 正在加载,控制台将在单击 canvasjs 图表时记录 url。
click: function (e) {
var asin = /*[[${asin}]]*/ 'null';
var url = "/FBTChartfbtrequest?fbt=2&asin=" + asin + "&collectdate=" + e.dataPoint.x;
console.log(url);
$("#fbtresult").load(url);
},
但是 $("#fbtresult").load(url); 没有执行以下控制器从日志中可以清楚地看到。
@GetMapping(value = "/FBTChartfbtrequest")
public String FBTChartfbtrequest(@RequestParam("fbt") String fbt,
@RequestParam("asin") String asin, @RequestParam("collectdate") String collectdate, Model model) {
System.out.println("ZZZZ requestFBTCHar with asin " + asin + " and collectdate " + collectdate);
...
model.addAttribute("fbts", fbtService.findByASINInFBT1andDateRange(asin, convertUtilToSql(date), convertUtilToSql(date)));
....
return "results :: fbtList";
}
我已确认在使用 window.location.href = 进行重定向时,我可以使用 /FBTChartfbtrequest?fbt=2&asin=" + asin + "&collectdate=" + e.dataPoint.x; url 加载新页面 =网址;
我的 pom.xml
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-rest</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>bootstrap</artifactId>
<version>3.3.4</version>
</dependency>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>jquery</artifactId>
<version>3.1.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
http://localhost:8086/FBTMetricsRequest 甚至在我单击图表之前就在网络选项卡中可见,并且单击图表不会在网络视图中进行更改。
知道为什么 jquery 加载函数没有调用控制器函数吗?
【问题讨论】:
-
你能检查你的网络日志吗,jquery 向服务器发送请求。根据我的假设,它应该向服务器发送请求。请发布网络日志截图。
-
@swarooppallapothu 我已经添加了屏幕截图
标签: javascript java jquery spring-boot thymeleaf