Use Ajax API provided by WordPress.
In first time, fix your Ajax request :
<script>
$(".post-link").click(function(){
var post_id = $(this).attr("rel"); //this is the post id
$("#post-container").html("content loading");
$.ajax({
url: myapiurl.ajax_url,
type: 'post|get|put',
data: {
action: 'my_php_function_name',
post_id: post_id
},
success: function(data) {
// What I have to do...
},
fail: {
// What I have to do...
}
});
return false;
});
</script>
Now, you have to create your WordPress treatment. You can put this code in your functions.php or in a plugin file.
add_action( 'admin_enqueue_scripts', 'my_ajax_scripts' );
function my_ajax_scripts() {
wp_localize_script( 'ajaxRequestId', 'myapiurl', array( 'ajax_url' => admin_url( 'admin-ajax.php' ) ) );
}
And then… your function that retrieve your posts
function my_php_function_name() {
// What I have to do...
}
PS: Never put code in root install folder. Use functions.php of your theme, or create plugin. It’s very important for maintainability and security. Have fun 🙂