为了从页面获取一些值,我遇到了一个小问题。
我有以下 jQuery UI 脚本:
$(function() {
$( "#dialog" ).dialog({
autoOpen: false,
show: "slideUp",
hide: "slideDown",
height: "300",
width: "400",
title: "Test pop-up",
buttons: {
"Close": function(){
$(this).dialog("close");
}
}
}
);
$( "p.diag").click(function(e) {
var monUrl = 'test2.php';
$.post("test2.php", { name: "test", time: "test" } );
$('#dialog').load(monUrl, function(response, status) {
$('#test_dialog').html(response);
pos = $("p.diag").attr("id");
});
$( "#dialog" ).dialog("open");
e.preventDefault();
});
test2.php 页面如下所示:
<?php
$var = $_POST['name'];
echo 'name = '.$var.'';
?>
我只想从我的 jQuery 脚本中检索“名称”值,但无论我做什么,$_POST['name']
仍然无效...
有什么线索吗?我是不是做错了什么?
谢谢!
最佳答案
您的代码中没有回调处理程序。
$.post("test2.php", { name: "test", time: "test" }, function(data) {
console.log(data);
});
关于php - 无法使用 jquery.post 获取值(发布),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11326362/