我想使用jquery发布数据并将其传递给同一PHP文件/页面中的PHP变量。
$(document).ready(function() {
$('.return_type').click(function(){
ret = $(this).val();
$.ajax({
url: "http://localhost:1000/globe/retrackView.php",
type: "POST",
data: {ret: ret},
success : function(results){
alert(results);
},
});
});
});
但是当我提醒结果时,它会提醒整个 HTML 标签。
$_POST["ret"];
并且$_POST["ret"]
为空
我需要
修改语法吗?提前感谢!
根据您的
评论,".return_type"您用于文本框。所以你应该使用 change() 而不是 click() 来绑定事件。如果在文本框上使用单击事件,它将立即在单击时调用(没有任何值)。
使用更改事件,而不是单击其文本框return_type。
$('.return_type').change(function(){
ret = $(this).val();
$.ajax({
url: "http://localhost:1000/globe/retrackView.php",
type: "POST",
data: {ret: ret},
success : function(results){
alert(results);
},
});
});