Reputation: 1137
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; the second one (GetEvent
) gets progress information from session every 500ms..
All of this works normally and the progress information is displayed correctly, but the process Servlet's callback never executes.
<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.
Upvotes: 0
Views: 447
Reputation: 14453
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.
http://api.jquery.com/jQuery.getJSON/
jQuery.getJSON( url, [data], [success(data, textStatus, jqXHR)] )
url A string containing the URL to which the request is sent.
data A map or string that is sent to the server with the request.
success(data, textStatus, jqXHR)A callback function that is executed if the request succeeds.
Try adding a valid url in place of "process" and if that fails use the $.ajax method as follows
$.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
},
});
Upvotes: 2