I would like to read a file (server-side) using jQuery. I have tried code supplied by multiple sites and it has not worked.
The code I tried last is:
jQuery.get("users/" + get("user") + "/display.txt", function(data) {
fullName = data;
});
However the variable 'fullName' (which is previously declared in the code) comes out as 'undefined'. How can I get this to work?
EDIT: Full code (excluding CSS)
<!DOCTYPE html>
<html>
<head>
<title>Chat</title>
<script src="jquery-1.11.3.min.js"></script>
<script type="text/javascript">
function get(variable) {
var query = window.location.search.substring(1);
var vars = query.split("&");
for (var i=0;i<vars.length;i++) {
var pair = vars[i].split("=");
if(pair[0] == variable){return pair[1];}
}
return(false);
}
var fullName;
var file = "users/" + get("user") + "/display.txt";
jQuery.get(file, function(data) {
fullName = data;
});
</script
</head>
<body bgcolor="#B2C2F0">
<div class="window">
<div class="rightCorner">
<span><script type="text/javascript">document.write(fullName)</script></span>
</div>
</div>
</body>
</html>