JQuery.ajax causes error return when accessing Spring Java service via URL based on domain name

My HTML5 application, jQuery Mobile frontend, is talking to a Java server (Spring, Hibernate, MySQL). The application works fine on my laptop as well as in the QA environment. In QA, I access the application using the server IP address. When I host an application in a Live environment (the same server as QA, but a different web application in Tomcat) and try to access it using a URL with a domain name, calls $ .ajax in the application return error.

One of the calls is as follows:

$.ajax({
   type : "GET",
   url : "http://www.smartcloudlearning.mobi:9080/SmartCloudLearningMobi/rest/resource/getResourceTypes",
   cache : false,
   async : false,
   dataType : 'json',
   success : function(rTypes) {
       Alert("success!");
   },
   error : function(XMLHttpRequest, textStatus, errorThrown) {
      alert("An error has occurred making the request: " + errorThrown);
   }
});

The following error appears in Firefox:

An error has occurred making the request: [Exception... "Component returned failure code: 0x80004005 (NS_ERROR_FAILURE)"  nsresult: "0x80004005 (NS_ERROR_FAILURE)"  location: "JS frame :: http://www.smartcloudlearning.mobi/js/jquery-1.7.1.min.js :: <TOP_LEVEL> :: line 4"  data: no]

In Chrome, the following error appears:

An error has occurred making the request: Error: NETWORK_ERR: XMLHttpRequest: Exception 101

In the server log, I see that the requested Spring service was started successfully, but it looks like the client is not receiving data!

If i click url

http://www.smartcloudlearning.mobi:9080/SmartCloudLearningMobi/rest/resource/getResourceTypes

, ! , - , Apache Tomcat.

httpd.conf Apache/httpd:

ProxyPass /SmartCloudLearningMobi http://www.smartcloudlearning.mobi:9080/SmartCloudLearningMobi
ProxyPassReverse /SmartCloudLearningMobi http://www.smartcloudlearning.mobi:9080/SmartCloudLearningMobi

- , ? !

:

.ajax, URL-. , "" URL- URL- QA. URL- .ajax, !

, "... ..." ... !

+3
3

, - , " ", . , , .

- AJAX Cross Domain

-, JSONP - JSONP

, JSONP:

$.ajax({
   url:"http://www.smartcloudlearning.mobi:9080/SmartCloudLearningMobi...",
   dataType: 'jsonp',
   ...
});
+4

URL: , URL- . .

$.ajax({
   type : "GET",
   url : "/SmartCloudLearningMobi/rest/resource/getResourceTypes",
   cache : false,
   async : false,
   contentType : "application/json"
   dataType : 'json',
   success : function(rTypes) {
       Alert("success!);
   },
   error : function(XMLHttpRequest, textStatus, errorThrown) {
      alert("An error has occurred making the request: " + errorThrown);
   }
});
+2

.ajax, URL-. , "" URL- URL- QA. URL- .ajax, !

Jason Foglia, your expression "... as well as the port ..." pushed me to explore this corner ... thank you very much!

0
source

All Articles