3

I'm working on a clientside project with jquery and javascript along with using jquery plugins. Our professor provided us with a proxy.php file to pull in data that we need to run the web app. I used the easy tab plugin which imported the jquery.min.js file. But I keep getting an error and the proxy.php file fails to load.

Here is the proxy.php file.

    <?php
    error_reporting(0);
    define ('HOSTNAME', 'http://simon.ist.rit.edu:8080/Services/resources/ESD');
    if($_POST['path']){
        $hold=explode('?',$_POST['path']);
        $path=$hold[0];
        $post=$hold[1]."&ip=".$_SERVER['REMOTE_ADDR'];
        $url= HOSTNAME.$path;
        $session = curl_init($url);
        curl_setopt($session, CURLOPT_HEADER, false);
        curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($session,CURLOPT_POST,1);
        curl_setopt($session,CURLOPT_POSTFIELDS,$post);
    }else{
        $url=HOSTNAME.$_GET['path'];
        $session = curl_init($url);
        curl_setopt($session, CURLOPT_HEADER, false);
        curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
    }
    $xml = curl_exec($session);
    header("Content-Type: text/xml");
    echo $xml;
    curl_close($session);
    ?>

These are the errors I keep getting. How do I fix this?

    XMLHttpRequest cannot load file:///C:/Users/Kubra/Desktop/Project2/proxy.php
?path=%2FCities%3Fstate%3DNY&_=1429379822193.
    Cross origin requests are only supported for protocol 
schemes: http, data, chrome, chrome-extension, https, 
chrome-extension-resource.   jquery.min.js:6

 Uncaught NetworkError: Failed to execute 'send' on 'XMLHttpRequest': 
    Failed to load 'file:///C:/Users/Kubra/Desktop/Project2
   /proxy.php? path=%2FCities%3Fstate%3DNY&_=1429379822193'.
Arkantos
  • 6,530
  • 2
  • 16
  • 36
  • Are you running this in server where your PHP file is located?? – Sandeep Nayak Apr 18 '15 at 18:14
  • Looks like there's problem with the URL you're using to fire the AJAX call in your client side javascript code. Change this `file:///C:/Users/Kubra/Desktop/Project2/proxy.php` to a valid URL. Also add your client side JS code for better resolution – Arkantos Apr 18 '15 at 18:15

1 Answers1

1

You cannot use XMLHttpRequest to load things from the local filesystem.

You need to host your website on an actual webserver.

See this answer for more information: xmlhttprequest for local files

Community
  • 1
  • 1
Norman Breau
  • 2,132
  • 16
  • 35