HTML / jQuery:
<a href=# id="friends">Friends</a>
<script type="text/javascript">
$(document).ready(function() {
$('a#friends').click(function() {
$.ajax({
type: "POST",
url: "data.php",
data: $('#friends').html(),
success: function(data) {
$('#questions').html(data);
},
dataType: "HTML"
});
});
});
</script>
data.php:
<?php
echo $_POST['#friends'];
?>
如何在锚标记中返回ID的POST
值?该变量正在传递给PHP,因为我可以发出警报,但问题是将其取回。
参考方案
您需要指定要在AJAX请求中发送的值的名称。尝试这个:
$.ajax({
type: "POST",
url: "data.php",
data: { 'friends': $('#friends').html() }, // Note the value is sent in an object with a key of 'friends'
success: function(data) {
$('#questions').html(data);
},
dataType: "HTML"
});
<?php
echo $_POST['friends']; // retrieve the 'friends' value
?>
Ajax Onchange在foreach循环内 - php我有ajax功能function price(id,prid,divid,key,name) { //alert(id); alert(prid); alert(name); $.ajax({ type: "POST", data: "aid="+id+"&prid="+prid, url:…
无法从jquery ajax()请求读取json对象 - php我已经浏览了好几次,无论如何都找不到适合我的答案,这是JS:jQuery.ajax({ url:'scripts/form.php?'+ 'name='+$('#name').val()+ '&comment='+$('#comment').val()…
如何保护免受恶意使用jQuery post handler? - php我使用jquery POST调用来获取要在网站各个部分中显示的数据。通常,它们将发布到单个“ ajax_handler.php”页面,该页面读取请求的参数并返回相关数据。典型的参数可能是“ get_order_details”,123我如何才能阻止用户发布到脚本来尝试检索他们不应该的数据?我知道我可以验证数据是否属于当前登录的用户,例如,但是如何阻止用户“猜…
jQuery AJAX fadeIn内容 - phpThis question already has answers here: Closed 7 years ago. Possible Duplicate: Making my ajax updated div fade in我希望将AJAX调用中的内容发送到页面上的fadeIn,但是当我使用此代码$('#sub_container')…
AJAX实时电子邮件验证(PHP) - php当用户在我的网站上创建帐户时,我希望对照我的数据库(MySQL)中的所有当前用户名检查输入的用户名,并确认是否可用。有谁知道我可以使用的任何好的库,或者是jQuery的插件? 参考方案 所需的确切信息以示例形式here给出。它使用jQuery作为JavaScript库