furry furry - 1 month ago 8
Javascript Question

Cannot execute get from javascript

I need execute get after timeout so I do

window.setTimeout(function() {
$.get("final.jsp");
}, 600);


but it does not execute at all
then I do next

window.setTimeout(function() {
$.get("appname/final.jsp");
}, 600);


It executes and canot find a path which is wrong


http://localhost:8080/appname/appname/final.jsp


so how can i actually make a
get
after delay?

Answer

If the URL you are trying to use $.get() with is this (which I'm just guessing because you haven't been entirely clear about that):

http://localhost:8080/grammar/final.jsp

Then, use:

window.setTimeout(function() {
    $.get("/grammar/final.jsp").then(function(result) {
        // process result here
    });
}, 600);

If you're actually trying to retrieve content with that Ajax call, then you will need to do something with the result of the ajax call.


If you're trying to open the URL in the browser (which your question does not actually say), then you don't use $.get() because that's an Ajax call. Instead, you would want to use either this:

// change current window to new URL
window.location = "http://localhost:8080/grammar/final.jsp";

or this:

// open new window (will probably get blocked by pop-up blocker)
// if done from setTimeout()
window.open("http://localhost:8080/grammar/final.jsp");
Comments