tags:

views:

714

answers:

4

I don't have any expirience in ajax functions of jQuery. I'm trying to make simple call like:

$.get ("ajaxsupport/login");

I have a servlet with url-pattern ("ajaxsupport/login").

When I type in browser's address field "http://localhost:9090/ajaxsupport/login" I see some result. But $.get (..) doesn't even make a call.

What is the problem?

I use jquery 1.3.1

+5  A: 

$.get is an asynchronous method call by default, meaning the caller remains in control. That's why something must happen, when the request has been executed. You specify that by defining a callback.

jQuery.get( url, [data], [callback], [type] )

In your case (note the prepended '/', it may not be necessary, depending on the scripts location, though):

<script type="text/javascript" charset="utf-8">
$(document).ready(function(){

    $.get("/ajaxsupport/login", 
        function(data, textStatus){ 
            // just prompt the response and the status message
            alert(data + "\n" + textStatus); 
        } 
    );

});
</script>
The MYYN
I tried with and without lead slash. Function is not beeing executed ever. There is no call to servlet, I don't know why.
Roman
maybe you can edit your question to include some more code (e.g. the $(document).ready ... enclosing and the imports)?
The MYYN
A: 

Get a tool like fiddler. Watch at how the request goes over the wire. Is it going to where you think it's going? Are you getting a response? Can you put a breakpoint on your web service call?

Dave Markle
+1  A: 

Try to find out if you get a result:

$(document).ready(function(){
 $.ajax
 ({
    type: "GET",
    url:"/ajaxsupport/login",
    success: function(result)
    {
        alert("I'm a success");
    }
});

});

You can also use firebug to what is requested and returned.

MrHus
A: 

Thanks to all.

Sorry, the problem was not in jQuery. There was a stupid bug and now it works fine.

Roman