<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8"/>
<title>
File uploader
</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
</head>
<body>
<form enctype="multipart/form-data" action="upload.php" method="POST" id="mainForm">
<input id="uploadImage" type="file" accept="image/*" name="image"/>
<input id="button" type="submit" value="Upload">
<br><br><br>
<textarea name="textarea" id="textarea"></textarea>
<textarea name="textarea" id="textarea_2"></textarea>
<button>ADD</button>
</form>
<div id="new" style="width:700px;height:900px;border:3px solid red;float:left;"></div>
<script>
$("#textarea").focus(function() {
var current_textarea = "textarea";
});
$("#textarea_2").focus(function() {
var current_textarea = "textarea_2";
});
$("#mainForm").submit(function (event) {
event.preventDefault();
var data = new FormData($('#mainForm')[0]);
$.ajax({
type: "POST",
url: "ajax.php",
data: data,
contentType: false,
processData: false
}).done(function (html) {
var currentVal = $("" + current_textarea + "").val();
$("" + current_textarea + "").val(currentVal + "<br>" + html + "<br>");
});
});
$("button").click(function() {
var text = $('#textarea').val();
$('#new').append(text);
});
</script>
</body>
</html>
<?php
$extensions = array('jpeg', 'jpg', 'png', 'gif');
$max_size = 500000;
$path = 'avatars/';
$response = '';
if (isset($_POST))
{
$ext = strtolower(pathinfo($_FILES['image']['name'], PATHINFO_EXTENSION));
$path = $path . uniqid() . '.' . $ext;
if (move_uploaded_file($_FILES['image']['tmp_name'], $path))
{
$response = "<img style='height: 200px;' src='$path'>";
}
}
echo $response;
?>
Это ajax загрузчик.Почему переменную current_textarea не видно???