[英]Button click to display a table from mysql in ibm mobile first
我正在學習,所以請幫助我首先通過單擊我的 html 頁面上的按鈕來幫助我在 ibm mobile 中從 mysql 中檢索表。 我已經嘗試過但沒有工作請幫助
<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<title>vikdemodb</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=0">
<!--
<link rel="shortcut icon" href="images/favicon.png">
<link rel="apple-touch-icon" href="images/apple-touch-icon.png">
-->
<link rel="stylesheet" href="css/main.css">
<script>window.$ = window.jQuery = WLJQ;</script>
</head>
<body style="display: none;">
<!--application UI goes here-->
<div id="header">
<h1>database Demo</h1>
</div>
<div id="wrapper">
<input type="button" id="databasecon" value="click me to get data from db" /><br />
</div>
<script src="js/initOptions.js"></script>
<script src="js/main.js"></script>
<script src="js/messages.js"></script>
</body>
</html>
我的 main.js
function wlCommonInit(){
$('#databasecon').click(loadSQLRecords);
}
function loadSQLRecords(){
var invocationData = {
adapter : 'vikadap',
procedure : 'getstudinfo',
parameters : []
};
WL.Client.invokeProcedure(invocationData,{
onSuccess : loadSQLQuerySuccess,
onFailure : loadSQLQueryFailure
});
}
function loadSQLQuerySuccess(result){
window.alert("success");
console.log("Retrieve success" + result);
console.log(result.invocationResult.resultSet);
}
function loadSQLQueryFailure(result){
WL.Logger.error("Retrieve failure");
}
你的 HTML 中有一個按鈕:
<input type="button" id="databasecon" value="click me to get data from db" />
你在wlCommonInit()
處理這個按鈕:
$('#databasecon').click(loadSQLRecords);
在loadSQLRecords()
您調用一個適配器過程來從數據庫中檢索數據。 如果此操作成功,則調用loadSQLQuerySuccess
回調函數。
您應該使用此函數處理來自后端(您的數據庫)的響應的顯示。 但是你在做什么? 您只將響應打印到控制台。 您根本不處理,將其顯示在應用程序中 - 在 HTML 中。
因此,在您的 HTML 中,您需要准備一個占位符,將結果附加到其中。 例如: <table id="mytable"></table>
然后你需要用數據填充表......
因此,在loadSQLQuerySuccess
,您可以例如執行以下操作...這是您需要學習 HTML 和 JavaScript 以完成您想要的樣子的地方:
function loadFeedsSuccess(result) {
if (result.invocationResult.resultSet.length > 0)
displayFeeds(result.invocationResult.resultSet);
else
loadFeedsFailure();
}
function loadFeedsFailure() {
alert ("failure");
}
function displayFeeds(result) {
for (var i = 0; i < result.length; i++) {
$("#mytable").append("<tr><td>" + result[i].firstName + "</td></tr>");
$("#mytable").append("<tr><td>" + result[i].lastName + "</td></tr>");
}
}
請注意,您需要在 for 循環中創建自己的代碼以使其看起來像您希望的樣子,當然還需要從數據庫中附加您自己的屬性,而不是“firstName”和“lastName”。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.