XMLHttpRequest cannot load and disable NetworkError

I am working on a client project with jquery and javascript together using jquery plugins. Our professor provided us with a proxy.php file to get the data we need to run the web application. I used a simple tab plugin that imported jquery.min.js file. But I keep getting the error and the proxy.php file is not loading.

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 to fix it?

    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'.

      

+3


source to share


1 answer


You cannot use XMLHttpRequest to download files from the local file system.

You need to host your website on a live web server.



See this answer for more information: xmlhttprequest for local files

+1


source







All Articles