我有1个php文件名index.php.在该文件中,我想将一个变量从ajax传递给php.
var elem = document.getElementById("mydiv").value;
(function($)
{
$(document).ready(function()
{
$.ajax(
{
type:"POST",
url: window.location.href,
data: 'action='+elem,
beforeSend: function() {
$('#cctv').hide();
},
complete: function() {
$('#cctv').show();
},
success: function() {
$('#cctv').show();
}
});
var $container = $("body");
$container.load('findAllPath.php',{'function': 'findAllPath'});
var refreshId = setInterval(function()
{
$container.load('findAllPath.php',{'function': 'findAllPath'});
}, 10000);
});
})(jQuery);
和我的PHP
if (isset ($_POST['action']))
{
echo $_POST['action'];
}
在firebug中,我可以看到ajax已经发布’action = value’但是在php中,$_POST [‘action’]是空的.
任何人都可以帮助我,我的代码有什么问题?
谢谢