Skip to content

Commit d581c66

Browse files
committed
j2sApplet.js Better message when CORS is not working
1 parent 0a98a72 commit d581c66

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

sources/net.sf.j2s.java.core/srcjs/js/j2sApplet.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -668,16 +668,24 @@ window.J2S = J2S = (function() {
668668
// the IMAGE option, which has been abandoned.
669669

670670
console.log("J2S._getRawDataFromServer " + J2S._serverUrl + " for " + query);
671-
672-
var s = "?call=getRawDataFromDatabase&database="
671+
if (database == "_" && J2S._serverUrl.indexOf("//your.server.here/") >= 0) {
672+
J2S.say("Info.serverURL has not been set. The url " + query + " is in a domain that requires Cross Origin Resource Sharing (CORS) access from this page, " +
673+
"and that domain is not recognized by SwingJS as allowing CORS access. If the server does allow CORS, " +
674+
"then the developer of this page must make sure that " +
675+
"J2S.addDirectDatabaseCall(path)" +
676+
" is called for that domain -- for example, J2S.addDirectDatabaseCall('stolaf.edu')." +
677+
" And if that domain does not allow CORS, then the developer should set Info.serverURL appropriately or contact the administrator of that domain to see if CORS can be allowed.");
678+
return "";
679+
}
680+
681+
var s = "?call=getRawDataFromDatabase&database="
673682
+ database
674683
+ (query.indexOf("?POST?") >= 0 ? "?POST?" : "")
675684
+ "&query="
676685
+ encodeURIComponent(query)
677686
+ (asBase64 ? "&encoding=base64" : "")
678687
+ (noScript ? "" : "&script="
679-
+ encodeURIComponent(J2S
680-
._getScriptForDatabase(database)));
688+
+ encodeURIComponent(J2S._getScriptForDatabase(database)));
681689
return J2S._contactServer(s, fSuccess, fError, infoRet);
682690
}
683691

0 commit comments

Comments
 (0)