javascript - How to call ajax from anonymous host, header Access-Control-Allow-Origin: * not working


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 means I take a free hosting from there, it I use the following PHP code

    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) {
    }"GET", "//", true);

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 No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin '' is therefore not allowed access.




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 browserinspect element you noticed there some extra code added by podserver.

People are also looking for solutions to the problem: PHP with MS sql server


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.