How to get a response from servlet via ajax?

Java-ajax cross site empty response string?

  • I am doing a cross-site ajax to java data transaction(Not sure if I named that correctly, so please forgive me about that). Part of code in Java file: BufferedReader input = new BufferedReader( new InputStreamReader (connectionsocket. getInputStream() ) ); DataOutputStream output = new DataOutputStream( connectionsocket.getOutputStream() ); ... output.writeChars("some random text"); output.close(); Also I have index.php file with some jQuery: $(document).ready(function() { $("#send_data").click(function(){ $.ajax({ type: 'get', dataType: 'text', url: 'http://localhost:1024/' + $("#command").val(), success: function(data) {console.log(data);}, error: function() { console.log("Error"); } }) }); }); The command is sent correctly and received in Java side correctly. Then the request from java to ajax is 200 OK too. The output is also working. (For example if I remove output.close(), I do see in the firebug, that it is waiting for the output to be closed.) The only problem is, no matter what I do I get no response text. It's always an empty string :(

  • Answer:

    you're adorable

kolibriz... at Yahoo! Answers Visit the source

Was this solution helpful to you?

Find solution

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.