如果不在监听搜索的keypress里面请求ajax的话,就会成功,想请教大佬.
<form class="mui-input-row mui-search">
<input id="searchInput" type="search" class="mui-input-clear" placeholder="">
</form>
<script type="text/javascript">
mui.init();
var text = document.querySelector('#searchInput');
text.addEventListener('keypress', function() {
var name = text.value;
if(name == '') {
plus.nativeUI.toast('搜索关键字不能为空!')
} else {
loadList(name);
}
});
/*请求列表数据*/
function loadList(name) {
var urlStr = encodeURI(name);
url = 'http://127.0.0.1:1500/Service/?name=' + urlStr;
mui.ajax(url, {
dataType: 'json',
type: 'get',
timeout: 10000,
success: function(data) {
console.log('success');
data = JSON.parse(data);
},
error: function() {
console.log("获取失败");
}
});
}
</script>
0 个回复