在SAP UI5应用里使用jQuery.ajax读取数据并显示在页面上

源代码:

<!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.

运行时结果:

汪子熙 CSDN认证博客专家 前端框架 Node.js SAP
JerryWang,2007年从电子科技大学计算机专业硕士毕业后加入SAP成都研究院工作至今。Jerry是SAP社区导师,SAP中国技术大使。2020年5月下旬,Jerry做了脑部肿瘤的开颅切除手术,对编程和人生又有了新的感悟。
已标记关键词 清除标记
©️2020 CSDN 皮肤主题: 博客之星2020 设计师:CY__ 返回首页