0

I am trying to retrieve from a servlet using Jquery

$(document).ready(function() {
    $("#mybutton").click(function(event) {
        alert('1');
        $.get("http://localhost:8888/ntlm/getuser", function(data) {
            alert('data ' + data);
            $(".errorMssg").text("Data Loaded: " + data);
            alert('data ' + data);
        });
        return true;
    });
});

and in GetUser servlet I have

public void doGet(HttpServletRequest request, 
                  HttpServletResponse response) throws ServletException, 
                                                       IOException {
    response.setContentType(CONTENT_TYPE);
            response.setContentType("text/html");
    PrintWriter out = response.getWriter();
    out.print("Authenticating?");
}

protected void doPost(HttpServletRequest request, 
                      HttpServletResponse response) throws ServletException, 
                                                           IOException {
    doGet(request, response);
}

If I directly access http://localhost:8888/ntlm/getuser, I am able to see output, however when I calling using Jquery, not able to see the output.

What could be the reason for this?

20
  • 1
    What does the console say? Commented Apr 12, 2013 at 7:06
  • @alkis Response is empty. Commented Apr 12, 2013 at 7:08
  • What does empty mean? You see alert('data') twice? Commented Apr 12, 2013 at 7:21
  • @PaulGrime I do not see alert('data') Commented Apr 12, 2013 at 7:24
  • Is the web page also on http://localhost:8888? Otherwise the browser will stop a cross-domain request (without special exception). Is the request sent? Does the server receive the request? Commented Apr 12, 2013 at 7:27

1 Answer 1

1

To perform cross-domain requests, e.g. a request to http://localhost:8888/ntlm/authenticate from a web page served from http://192.168.1.2:8988, you will either need to enable CORS or use JSONP.

jQuery JSONP.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks Paul for your solution.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.