設置請求按鈕事件
<button id="jumpPage" onclick="jumpPage()" class="btn btn-primary btn-pill" >跳轉</button>
請求處理,想服務器請求
function jumpPage() {
var dbName = document.getElementById("selectDataBase").value; //數據庫下拉框對象
var tbName = document.getElementById("selectTable").value;
$.ajax({
url: "db/index", //請求路徑
type: "post",
data: {dbName:dbName,tbName:tbName}, //頁面參數
success: function (data) {
alert(data); //顯示返回的數據
}
})
}
服務器接收ajax請求,並自動返回至頁面
@Controller
@RequestMapping("/db")
public class DbConfigController {
@Autowired
@Qualifier("dbConfig")
private DbConfigService dbConfigService; //數據庫配置
@RequestMapping("/index")
public String index(HttpServletRequest request){
return "index";
}