[英]JQuery callback not executed?
I want to have a progressbar that take data from server, so I created 2 servlets the first one ( process
) starts the process and when it ends return the result; 我想有一个从服务器获取数据的进度条,所以我创建了2个servlet,第一个(
process
)启动进程,结束时返回结果; the second one ( GetEvent
) gets progress information from session every 500ms.. 第二个(
GetEvent
)每500ms从会话中获取进度信息..
All of this works normally and the progress information is displayed correctly, but the process Servlet's callback never executes. 所有这些都正常工作,并且正确显示了进度信息,但进程Servlet的回调从不执行。
<html>
<head>
<link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="stylesheet" type="text/css"/>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script>
<script>
$(document).ready(function() {
process();
$("#progressbar").progressbar({ value: 0 });
$("#progressStatus").html("");
getEvent();
});
function process()
{
$.getJSON("process", function(result){
//never executed
alert( "Result: " );
});
}
function getEvent()
{
$.getJSON("GetProgressEvent", function(data) {
$.each(data.ProgressEvents, function(){
$("#progressbar").progressbar({ value: this.progress });
$("#progressStatus").html(this.status);
});
});
setTimeout(getEvent, 500);
}
</script>
</head>
<body style="font-size:62.5%;">
<div id="progressbar"></div>
<div id ="progressStatus"></div>
</body>
</html>
I just started with JQuery and I don't know what's wrong with this code. 我刚开始使用JQuery,我不知道这段代码有什么问题。
you are calling $.getJSON with a url "process" this function has no error handling if there is problem with the response or invalid JSON is returned then the callback will not be called. 你正在使用url“process”调用$ .getJSON这个函数没有错误处理,如果响应有问题或者返回了无效的JSON,那么将不会调用回调。
http://api.jquery.com/jQuery.getJSON/ http://api.jquery.com/jQuery.getJSON/
jQuery.getJSON( url, [data], [success(data, textStatus, jqXHR)] ) jQuery.getJSON(url,[data],[success(data,textStatus,jqXHR)])
url A string containing the URL to which the request is sent. url包含发送请求的URL的字符串。
data A map or string that is sent to the server with the request. data与请求一起发送到服务器的映射或字符串。
success(data, textStatus, jqXHR)A callback function that is executed if the request succeeds. success(data,textStatus,jqXHR)如果请求成功则执行的回调函数。
Try adding a valid url in place of "process" and if that fails use the $.ajax method as follows 尝试添加有效的URL代替“进程”,如果失败则使用$ .ajax方法,如下所示
$.ajax({
url: "mydomain.com/url",
type: "POST",
dataType: "json",
data: $.param( $("Element or Expression") ),
complete: function() {
//called when complete
},
success: function() {
//called when successful
},
error: function() {
//called when there is an error
},
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.