这是我的html-js页面代码
$(document).on('pageinit', '#mainpage', function () {
$(document).ready(function () {
$("#login").click(function () {
$.mobile.changePage("#authpage", {
transition: "slide",
changeHash: false
});
});
});
var uri2 = 'api/CEP/AuthenticateUser'
function find() {
var userid = $('#UserID').val();
var pass = $('#Password').val();
var reqType = $('#RequestType').val();
var data = {
strUser: userid,
strPassword: pass,
strReqType: reqType
};
$.getJSON(uri2, data)
.done(function (data) {
$('#User').text(formatItem2(data));
})
.fail(function (jqXHR, textStatus, err) {
$('#User').text('Error: ' + err);
});
}
function formatItem2(item2) {
return 'Emp ID: ' + item2.EmpID + ' RequestType: ' + item2.ResultMsg + ' Name: ' + item2.EmpName;
}
<div id="authpage" data-role="page">
<div data-theme="a" data-role="header">
<a href="#mainpage" class="ui-btn-left" data-transition="slide" data-direction="reverse">Back</a>
<h3>
LOGIN
</h3>
</div>
<div class="table-thing with-label widget uib_w_5 d-margins" data-uib="jquery_mobile/input" data-ver="0">
<label class="narrow-control label-inline">UserID</label>
<input class="wide-control" placeholder="Your UserID" type="text" id="UserID">
<label class="narrow-control label-inline">Password</label>
<input class="wide-control" placeholder="Your UserID" type="Password" id="Password">
<label class="narrow-control label-inline">RequestType</label>
<input class="wide-control" placeholder="Your UserID" type="text" id="RequestType">
<a class="widget uib_w_3 d-margins" data-uib="jquery_mobile/button" data-ver="0" data-role="button" id="btnclk" href="newpage" onclick="find();">Login</a>
</div>
<div data-role="content">
<div data-iscroll>
<ul data-role="listview" id="authlist" data-divider-theme="b"></ul>
</div>
</div>
</div>
答案 0 :(得分:0)
您可能无法通过浏览器&#34;由于远程服务器上的跨域限制到位以防止滥用。英特尔提供了图书馆以规避这些限制并允许访问,只需在您的应用程序标题中包含这些:
<script src="intelxdk.js"></script>
<script src="xhr.js"></script>
有关如何从混合应用程序访问JSON的更多信息,请访问: https://software.intel.com/en-us/html5/articles/how-to-access-JSON-data-in-HTML5-apps
如果您仍然遇到问题,请尝试跳过$ .getJSON并尝试直接使用getRemoteDataExt方法进行试验,并附带一个事件监听器: https://software.intel.com/en-us/node/493009
答案 1 :(得分:0)
除非你正在做“遗留”版本而不是cordova,否则你不再需要xhr.js. Ajax调用应该可以正常工作,在Cordova容器中使用getRemoteData(Ext)会更好。
如果你能发布一个更好的例子,我会很乐意测试它。尝试在jsbin中设置我可以在英特尔®XDK中测试的设置。