I am trying to write output from PHP script hosted on another domain (HTTPS).
Here is my PHP file:
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: GET, POST');
header("Access-Control-Allow-Headers: X-Requested-With");
echo "lol";
Here is my HTML code (on another domain):
<script>
var data_from_ajax;
$.get('LINK/script.php', function(data) {
data_from_ajax = data;
});
document.write(data_from_ajax);
</script>
The later aim is to pass back URL variable and then produce different output.
However, currently - the document.write
returns "undefined
".
ur getting "undefined" cause "document.write" is called before the callback.