In HTML, there is a textarea
. When textarea
content is edited, I need the AJAX to read an external file and alert its content. I have this code which doesn't alert anything:
<!DOCTYPE html>
<textarea id="area">Sample Text</textarea>
<!-- Include jquery -->
<script src="https://code.jquery.com/jquery-3.1.1.slim.min.js" integrity="sha384-A7FZj7v+d/sdmMqp/nOQwliLvUsJfDHW+k9Omg/a/EheAdgtzNs3hpfag6Ed950n" crossorigin="anonymous"></script>
<script type="text/javascript">
$("#area").on("change keyup paste", function() {
$.ajax({
method: "POST",
url: "externalFile.php",
data: { content: $("#area").val() }
})
.done(function( msg ) {
alert( "Reading Data: " + msg );
});
});
</script>
However, I know that the code successfully enters the jquery function because the following test alert works when I start typing in the textarea:
<textarea id="area">Sample Text</textarea>
<!-- Include jquery -->
<script src="https://code.jquery.com/jquery-3.1.1.slim.min.js" integrity="sha384-A7FZj7v+d/sdmMqp/nOQwliLvUsJfDHW+k9Omg/a/EheAdgtzNs3hpfag6Ed950n" crossorigin="anonymous"></script>
<script type="text/javascript">
$("#area").on("change keyup paste", function() {
alert("Test Alert");
});
</script>
The external file is in the same directory - externalFile.php
This text is in external file!
Am I doing something wrong in the AJAX part?