这是我的预览问题的一个更清晰的代码,它的想法是使用ajax发送和检索值,但该值没有被发送,也没有Ajax似乎工作。我更新了这个代码,因为这样可以很容易地在任何机器上测试它。第一次使用ajax。下面是代码:使用ajax发送和检索值问题
的Javascript
<script>
jQuery(document).ready(function() {
jQuery('#centro').click(function() {
$.ajax({
url: 'request.php',
type:'POST',
data: $("#form").serialize(),
dataType: 'json',
success: function(output_string){
alert(output_string);
$('#cuentas').html(output_string);
} // End of success function of ajax form
}); // End of ajax call
});
}
});
</script>
HTML:
<?php
$result = 'works';
?>
<form id="form">
<div id="centro">
<a href="#">Click here</a>
<br>
<input type="hidden" name="centro" value="<?php echo $result; ?>">
</form>
<div id="cuentas">
</div>
PHP文件,request.php
<?php
$centro = $_POST['centro'];
$output_string = ''.$centro;
echo json_encode($output_string);
?>
什么'的var_dump($ _ POST);' – 2013-05-01 15:55:21
其中@HankyPanky? – 2013-05-01 15:57:07
在你的'load_cuentas.php'之上,放上'var_dump($ _ POST);'并且看看它首先得到了什么值?并请与我们分享输出 – 2013-05-01 15:59:19