ajax1.php
<input type="button" id="goal" />
<script src="jquery.js"></script>
<script>
$('#goal').click(function() {
$.ajax({
url: "ajax2.php",
type: "POST",
data: {id:123},
dataType: "json",
success: function(){
window.location.href = 'ajax2.php';
},
error: function() {
alert( "Sorry, there was a problem!" );
}
});
});
</script>
我将如何从ajax2.php处理这个data: {id:123}
?
另外,我想问一下我将如何将变量(我将进入ajax2.php)发送回ajax1.php。
答案 0 :(得分:0)
您可以通过$_POST['id']
访问ajax2.php中的参数,然后在您的php中可以回显您的结果。
如果需要返回多个值,可以创建一个JSON对象,然后在成功回调中,您可以解析JSON来操作数据
PHP
<?php
if ($_POST['id'] == 123) {
echo "Found";
}
else {
echo "Missing"
}
?>
的jQuery
success: function(data) {
if(data == "Found") {
alert("Record was found");
}
}