這裏是我做的:jQuery和PHP的AJAX會議
我的登錄表單是www.mysite.com/login.html:(!子域名WWW)
function authenticate(userName, password) {
$.ajax
({
type: "POST",
//the url where you want to sent the userName and password to
url: 'http://server.mysite.com/ajax/auth.php',
dataType: 'json',
async: false,
cache: false,
data: 'vardas='+userName+'&psw='+password,
success: function (data) {
{
window.location.replace('/main.html');
}
}
})
}
這裏是我的AJAX/auth.php:
header('Content-type: application/json');
header ("Access-Control-Allow-Origin: http://www.mysite.com");
header('Expires: ' . gmdate('r', 0));
session_start();
$_SESSION["ok"] = 1111; <- test value
這裏是main.php:
<script>
$(function() {
$('#home').load('http://server.mysite.com/ajax/loader.php', function() {
})
});
</script>
<div id=home></div>
這裏是我的AJAX/loader.php :)
<?
header ("Access-Control-Allow-Origin: http://www.mysite.com");
header('Expires: ' . gmdate('r', 0));
session_start();
var_dump ($_SESSION); <---- OUTPUT IS (0) EMPTY!! Why ?
?>
爲什麼這一點兒也不工作?我總是得到$ _SESSION空的。
你已啓用Cookie? –
是的,它已啓用。 – Dikobraz
這是跨域還是在同一個域中? –