如何使用我動態加載的javascript加載我的php在我的域中。從動態javascript動態加載php
我的示例代碼
sample.html(客戶端)
<div onClick = "getThis()"></div>
my.js(客戶端)
function getThis(){
var url = "http://www.sampledomain.com/test.js"
var script = document.createElement('script');
script.src = url;
document.head.appendChild(script);
}
test.js(服務器端)
$.get("index.php", function(data) {
alert(data);
});
index.php(Server-side)
<?php
$_SESSION['user'] = "rob098";
?>
<script>
var data = '<?php echo json_encode($_SESSION['user']) ?>';
</script>
但它沒有提醒任何。
TNX爲提示,會保留在我的頭上。但仍然沒有奏效。 –