AJAX is not working properly after moving on localhost

早过忘川 提交于 2020-01-06 19:26:17

问题


I have an issue with my simple testing code. Everything was fine on remote server, it starts when I moved to localhost(xampp)

I have a page:

http://localhost/test/test.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title>NeedNext - Try It</title>
<script type="text/javascript" src="javascript/jquery.js" ></script>
<script type="text/javascript">  
$().ready(function() {
    $("#listinx").load("ajax.php",{variable : "WTF"})
}); 
</script>
</head>
<body>
<div id="listinx"></div>
</body>
</html>

called http://localhost/test/ajax.php contains:

<?php
echo "heh?";
echo $variable;
?>

I suppose the result in browser should be: "heh?WTF" but it's only "heh?". Any ideas what's wrong? Please let me know, Thanks, Michal


回答1:


Have you tried:

echo $_REQUEST['variable'];

?




回答2:


You don't have register_globals enabled.
Therefore, you cannot implicitly get POST parameters by writing $variable.

Change your code to echo $_POST['variable'].

You should also disable it on your server:

Warning

This feature has been DEPRECATED as of PHP 5.3.0. Relying on this feature is highly discouraged.

It will usually create security holes.



来源:https://stackoverflow.com/questions/4985997/ajax-is-not-working-properly-after-moving-on-localhost

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!