Accessing Client's 'localhost' from JavaScript Online

后端 未结 5 780
旧时难觅i
旧时难觅i 2021-01-05 09:01

this is what I am trying to do.

  1. I have made a few .html pages with JavaScript code in it and hosted them on a Yahoo server.

  2. Now when a clien

5条回答
  •  一整个雨季
    2021-01-05 09:42

    The local machine also needs a proxy set up that maps "http://localhost:8080/whatever" to the yahoo pages with your Ajax code. In order for the code to work, you must load it in the browser using the domain same domain that it tries to access.

    I'm not sure how to do this with Tomcat (?), but one option is to use Apache to proxy both the Tomcat server and the Yahoo pages into the same location.

    In Apache, this looks like:

    LoadModule proxy_module modules/mod_proxy.so
    LoadModule proxy_http_module modules/mod_proxy_http.so
    ...
    
      ProxyRequests off
      ProxyPass /static    http://yahoo.com/path
      ProxyPass /myservlet http://localhost:8080/myservlet
    
    

    You would then load your HTML from localhost/static, and those pages would be able to make AJAX requests to localhost/myservlet.

提交回复
热议问题