我在PHP中执行Get Request以获取某个值,然后我将这个值输入到textfield的值中,我有了text-fields值然后调用json请求。
它适用于输入和更改,但适用于页面加载。以下是代码:
$(document).ready(function() {
var runningRequest = false;
var request;
$('input#asd3').on('load', function(e) {
var $q = $(this);
if(runningRequest){
request.abort();
}
runningRequest=true;
var myString = self.location.href;
var mySplitResult = myString.split("?");
request = $.getJSON('search',{q:$q.val()},function(data){
showResults(data,$q.val());
showResults2(data,$q.val());
runningRequest=false;
});
});
});
html
<input type="text" id="asd3" name="asd3" value="<?php echo $name ?>" class="form-control" autocomplete="off" placeholder="Search Name..." class="input-block-level" placeholder="Search..." style="width:100%; display:none;" />
答案 0 :(得分:0)
https://developer.mozilla.org/en-US/docs/Web/Events/load
load事件主要与属于外部资源的元素相关。窗口文档,图像,iframe等。输入元素不依赖于任何类似的东西,也不会有加载事件。
如果您希望逻辑在“页面”加载时发生,那么您应该绑定到窗口或文档。尝试改变......
Runnable
到
@Override
public void run(){
try{
while (paused) {
synchronized(this) {
wait(); // keep sleeping this thread while the state is still paused
}
}
controller.runOnTimer();
} catch (IOException e) {
e.printStackTrace();
}
}