Making an AJAX request to another server

后端 未结 4 690
小蘑菇
小蘑菇 2020-12-10 02:38

I have AJAX code where if you request an AJAX call to remote server the request fails:

function loadXMLDoc() {
  if (window.XMLHttpRequest) {
    // code for         


        
4条回答
  •  [愿得一人]
    2020-12-10 03:26

    I wanted to post another variation on the top answer. I tried to use ProxyPass in my .htaccess file but I kept getting Internal Service Errors. Finally after some reading I discovered there was another way to do this with the rewrite engine.

    RewriteEngine On
    RewriteRule ^mail.php$ http://otherwebsite.com/mail.php [P,L]
    

    The P in [P,L] tells the rewrite system that its using mod_proxy. This worked for me and I didn't get internal server errors.

    The advantage to this approach is since it's using the Rewrite Engine, you have more control over the variables you might need to dynamically send to the script.

提交回复
热议问题