0

Hello i am trying to create a PHP page that can be called by ajax from anonymous host, I run my code XAMPP host and working nice, But when i try to run it from http://podserver.info/ means I take a free hosting from there, it is www.datatwo.podserver.info. I use the following PHP code

<?php 
    header('Access-Control-Allow-Origin: *');
    header('Access-Control-Allow-Methods: GET, POST, OPTIONS');
    header('Access-Control-Allow-Headers: Origin, Content-Type, Accept,Authorization, X-Request-With');
    header('Access-Control-Allow-Credentials: true');
    echo "hi";
?>

and JavaScript ajax code is

var xmlhttp;

    if (window.XMLHttpRequest) {
        // code for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttp = new XMLHttpRequest();
    } else {
        // code for IE6, IE5
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.onreadystatechange = function() {
        if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
            console.log(xmlhttp.responseText);
        }
    }
    xmlhttp.open("GET", "//www.datatwo.podserver.info/index.php", true);
    xmlhttp.send();

but it only work when I use XAMPP server and when I upload it to pod server it dos not work, what can I do now?

A error message from console XMLHttpRequest cannot load http://www.datatwo.podserver.info/index.php. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://stackoverflow.com' is therefore not allowed access.

  • Possible duplicate of [jQuery AJAX cross domain](http://stackoverflow.com/questions/3506208/jquery-ajax-cross-domain) – Popnoodles Dec 13 '15 at 18:19
  • *"it dos not work"* is not enough information to help you. Please read [ask] and provide more information. – Felix Kling Dec 13 '15 at 18:31

1 Answers1

0

When you call ajax podserver don't give you main output from your PHP, server first convert your php to their format you can understand that using browser inspect element you noticed there some extra code added by podserver.