Unable to receive HTTP Response within a local Javascript file function.

from Client Javascript file , JavaScript , Ajax Call India
  • 9 years ago


    I have developed a Java desktop application and I am making an Ajax call to a Web application, which resides on the Server. I am sending my Http request through the xmlHttpReq in a Javascript function.

    This Javascript file is on my local machine. I need to make an HTTPRequest via Ajax to my Web application on Server.

    The Ajax call is being made through a Javascript function, where an Http Request is being sent to the Server. The Server has a deployment of the Java Struts 2.0 Framework Web application. The Struts 2 controller is able to invoke an Action written in Java, once it receives the Http Request from Javascript function, which is an Ajax call.

    Here is a code snippet example of how we are doing this:

    function myJavaScriptFunction() { ….. ….. strURL = ‘ http://localhost:8080/HelloWorld/HelloWorldAction’ self.xmlHttpReq.open('post', strURL, true); self.xmlHttpReq.setRequestHeader('Content-Type','application/jsonrequest'); self.xmlHttpReq.onreadystatechange = function() { if (self.xmlHttpReq.readyState == 4) { alert(‘RESPONSE: ‘ + self.xmlHttpReq.responseText); } } self.xmlHttpReq.send(requestData); }

    Once this block of code is executed in Javascript, the desired Java Action is invoked and a Response is being built. The Response is as required in the Java action class.

    However, the Response object is not received at the client side Javascript file, in the function, from where we sent out the Http Request. Here, we are receiving an Empty Response object.

    *Note: This Ajax Calling of HTTP Request and Response is successfully executed if the Javascript file is kept inside the Web application on the Server.) *

Post a reply

No one has replied yet! Why not be the first?

Sign in or Join us (it's free).


Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Nine people can't make a baby in a month.” - Fred Brooks