CORS header 'Access-Control-Allow-Origin' missing in


CORS header 'Access-Control-Allow-Origin' missing in php

在我的web应用程序中,尝试通过ajax调用将数据传递到另一个域。但它显示了Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://example.com/auth/webschool/test.php. (Reason: CORS header 'Access-Control-Allow-Origin' missing).

这样的错误我的ajax代码是,
 $.ajax({
                type: "POST",
                url: "http://example.com/auth/webschool/test.php",
                data: {username: "abcd",password:"abcd"},
                 dataType: "html",
                success: function (data) {
                 alert(data);
                }
            });

把这行放到test.php里,希望能行

<?php header('Access-Control-Allow-Origin: *'); ?>