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

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

    Hi,

    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).

Contribute

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.

“It is practically impossible to teach good programming style to students that have had prior exposure to BASIC. As potential programmers, they are mentally mutilated beyond hope of regeneration.” - E. W. Dijkstra