AJAX未链接到PHP文件

I need to change a session value inside a JavaScript function so I decided to use AJAX. However, the call does not seem to be working. What is wrong?

Index page setting default session value:

session_start();
if( is_null($_SESSION['lang']) ){
    $_SESSION['lang'] = 'english';
}

AJAX call on index page:

var request = new XMLHttpRequest();
request.open('GET', 'setlang.php?entry=0', false);
request.send();

The setlang.php file:

$entry = $_GET['entry'];
if($entry == 0){
    $_SESSION['lang'] = 'english';
    Print_r ($_SESSION);
}else if($entry == 1){
    $_SESSION['lang'] = 'japanese';
    Print_r ($_SESSION);
}

Nothing is being printed. Does anyone know what is wrong?

查看全部
weixin_33695450
weixin_33695450
2013/09/18 14:13
  • php
  • ajax
  • javascript
  • 点赞
  • 收藏
  • 回答
    私信

2个回复