源代码:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta charset="utf-8">
<title>SAPUI5 Sandbox</title>
<script
id="sap-ui-bootstrap"
src="https://openui5.hana.ondemand.com/resources/sap-ui-core.js"
data-sap-ui-theme="sap_belize"
data-sap-ui-libs="sap.m,sap.ui.layout"
data-sap-ui-compatVersion="edge"
data-sap-ui-preload="async">
</script>
<script>
sap.ui.getCore().attachInit(function () {
var oInput = new sap.m.Input({
liveChange : function(oEvent) {
console.log('live change event: ' + oEvent.getParameter('newValue'));
}
});
var oVerticalLayout = new sap.ui.layout.VerticalLayout();
oVerticalLayout.addContent(oInput);
var oText = new sap.m.Text();
oVerticalLayout.addContent(oText);
//oText.setText('response');
oVerticalLayout.placeAt("content");
var html = jQuery.ajax({url:"s5.xml",async:false});
oText.setText(html.responseText);
// console.log('response: ' + html.responseText);
});
</script>
</head>
<body class="sapUiBody" role="application">
<div id="content"></div>
</body>
</html>
url:http://localhost:3000/wt/livesearch.html
注意,不能本地直接打开livesearch.html, 否则会遇到跨域问题:
Access to XMLHttpRequest at ‘file:///C:/Code/jerrylist/walkthrough/s5.xml’ from origin ‘null’ has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, chrome-untrusted, https.
运行时结果: