It is completly possible... the problem you have is the condition in the file wrapper.php
.
You are trying to validate some variables defined in the index.php
but you're loading that page by ajax which implies that these variables are not available in the file wrapper.php
Load an ajax page is almost the same load that page directly in the browser.
So this is definitely not the best and secure way to validate a login action.
Now.. for OP code, main question and some explanations already given, I must add:
index.php
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
</head>
<body>
<div id="content">dummy text</div>
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
<script type="text/javascript">
$(function() {
$("#content").load("wrapper.php?target=login");
});
</script>
</body>
</html>
wrapper.php
<?PHP
$target = $_GET['target'];
require_once $target.'.php';
?>
login.php
<?PHP
echo "I'm in!";
?>
Result of index.php in browser:
<div id="content">I'm in!</div>
So the logic works, but IMHO, is not suitable for this purpose.