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; 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.
-
Answer:
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 }, });
user405458 at Stack Overflow Visit the source
Related Q & A:
- How to link inside a specific jquery tab?Best solution by Stack Overflow
- How to clone once with JQuery clone?Best solution by Stack Overflow
- How to Search using jQuery ASP.Net?Best solution by Stack Overflow
- How to implement C callback function in Swift?Best solution by pr8x.com
- What is closure in Swift? Is it similar to callback in Javascript?Best solution by developer.apple.com
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.