$.ajax({
type:"POST", //默认值: "GET")。请求方式 ("POST" 或 "GET"), 默认为 "GET"
url:"index.php", //当前页地址。发送请求的地址
dataType: "json",
cache: true,
data:JSON.stringify({
'goodsNum':1}),
success:function(data){
if(data){
alert(data);
//window.location.reload();
}
},
async:false, //true为异步请求,false为同步请求
error:function(){
alert("请求失败");
}
});
我现在改了一下
js中:
$.ajax({
url:"index.php", //当前页地址。发送请求的地址
type:'POST', //默认值: "GET")。请求方式 ("POST" 或 "GET"), 默认为 "GET"
cache: false,
data:{'goodsNum':1},
success:function(data){
if(data){
alert(data);
}
},
//async:false, //true为异步请求,false为同步请求
error:function(){
alert("请求失败");
}
});
php中:
if($_POST['goodsNum']){
$num = $_POST['goodsNum'];
$title = $dou[$num-1][2];
echo $title;
$content1 = $dou[$num-1][3];
echo $content1;
}
这里echo不出现在网页中,而是出现在ajax请求成功的提示框中
然后在html中显示$title
<?php echo $title; ?>
显示不出