我想要做一个简单的AJAX函数从查询字符串发送数据,并追加DIV。 。我尝试了各种不同的方法,但没有更新div。如果它更新,它将返回NULL,否则它会转到request.php页面。如果我在click事件下移动预设的默认功能,它什么也不做。 任何帮助将不胜感激! TIA在ajax函数中使用查询字符串
<script type="text/javascript" src="js/jquery-1.7.1.min.js"></script>
<script type="text/javascript">
$(function()
{
$("#link").click(function(e)
{
$.ajax(
{
type : "GET",
url : "request.php",
data : { id: link.attr('id') },
success : function(response)
{
$("#ajaxresponse div").fadeOut("fast", function()
{
$("#ajaxresponse div").remove();
$("#ajaxresponse").append($(response).hide().fadeIn());
});
}
});
e.preventDefault();
});
});
</script>
</head><body>
<h1>
AJAX with PHP
</h1>
<div class="content">
<a href="request.php?id=1" id="link" data-id="1" >Submit Link</a>
</div>
<div id="ajaxresponse">
<div>please submit the form</div>
</div>
的request.php如下:
<?php
$username = $_GET['id'];
echo getTemplate($username);
function getTemplate($username)
{
return '<div class="box">
<h1>The ID is</h1>
<div class="meta">username: '.$username.'</div>
</div>';
}
?>
什么数据,如果你直接访问的URL,并在URL的到底是什么在'response' –
我只是想发送“1”:request.php ID = 1 – Jjames