I am trying to get my data from a query string, but use it with Ajax.
I cant seem to get the data passed correctly and I am wondering where my syntax is wrong:
$(function()
{
$("#link").click(function(event)
{
event.preventDefault();
$.get("request.php",{id:+link.attr('id')},function(response){
$("#ajaxresponse div").fadeOut("fast", function()
{
$("#ajaxresponse div").remove();
$("#ajaxresponse").append($(response).hide().fadeIn());
});
}
});
return false;
});
});
The html page code:
<div class="content">
<a href="request.php?id=1" id="link">
</div>
Am I not structuring the data to the ajax call correctly??
Thanks in advance
I can get it to return properly, but not in Ajax fashion, it is still loading the .php page instead of appending it, here is the request.php side of things:
$username = $_GET['id'];
echo getTemplate($username);
function getTemplate($username)
{
return '<div class="box">
<h1>ID is</h1>
<div class="meta">username: '.$username.'</div>
</div>';
}
add this function outside any other function :
then use :
instead of
demo : http://jsfiddle.net/zY9s2/