I currently have an ajax call after a user presses a button
on my web page..
The problem is, that after submitting, there is a slight delay (as a second ajax call needs to complete to show the DIV) to avoid a slight lag.. I was wondering if it was possible to append the content to a DIV:
<textarea name='Status'> </textarea>
<input type='hidden' name='UserID' value="<?=$_SESSION['UserID']; ?>">
<input type='button' value='Status Update'>
<script>
$(function () {
$('input').on('click', function () {
var Status = $(this).val();
$('#output').append(Status);
});
</script>
The above is my current code configuration. Now, this does not work as expected. It does not add the submitted content to the DIV.. here is how it's displayed through my ajax call:
window.setInterval(function()
{
$(function ()
{
$.ajax({
url: 'Ajax/AjaxStatuses.php', data: "", dataType: 'json', success: function(rows)
{
$('#output').empty();
for (var i in rows)
{
var row = rows[i];
var User = row[0];
var Status = row[1]
$('#output').append(''+
'<div class="small-3 large-2 columns "><img src="http://placehold.it/80x80&text=[img]" /></div>'+
'<div class="small-9 large-10 columns">'+
'<p><strong><a href="#">'+User+'</a>:</strong>'+Status+'</p>'+
'<ul class="inline-list">'+
'<li><a href="">Reply</a></li>'+
'<li><a href="">Share</a></li>'+
'</ul><hr>');
}
}
});
});
}, 1000);
and the call:
include "../PHP/Database.php";
$Array = array();
$Query = $DB->prepare("SELECT UserID, Text FROM statuses Order BY ID DESC");
$Query->execute();
$Query->bind_result($ID, $Text);
$Query->store_result();
while($Query->fetch()){
$Second_Query = $DB->prepare("SELECT Username FROM users WHERE ID=?");
$Second_Query->bind_param('i',$ID);
$Second_Query->execute();
$Second_Query->bind_result($Username);
$Second_Query->fetch();
$Array[] = array ($Username, $Text);
$Second_Query->close();
}
$Query->close();
How do I append the text area to a HTML div after pressing the button so my script doesn't have to wait for a response from the newly posted status?
Update. When the button is submitted it calls the following code:
$(function () {
$('input').on('click', function () {
var Status = $(this).val();
$.ajax({
url: 'Ajax/StatusUpdate.php',
data: {
userid: $("input[name=UserID]").val(),
text: $("textarea[name=Status]").val(),
Status: Status
},
dataType : 'json'
});
});
});
To handle the ajax input