I have this jquery post that takes text from a textarea and inputs it into a mysql database and then changes a div value. This is all done when a button is clicked. The jquery function is:
$('#editAnswerSubmit').click(function(e){ //the button
e.preventDefault();
var edited_answer = $('#modalEditAnswer').val();
$.post('../submiteditanswer.php' , {edited_answer: edited_answer , answer_id: answer_id} , function(response){
answer.val(response);
$('#editAnswerModal').modal('hide');
});
});
I have alert() all of the variables when the button was clicked and the correct values appeared so there must be something wrong with the post code itself. I also had an alert('test') after the post but before the first response and it never appeared.
Contents of submiteditanswer.php:
<?php
include 'connect.php';
$answerID=$_POST['answer_id'];
$sql=mysql_query("UPDATE answers SET time='2' WHERE id='$answerID'");
$edited_answer=mysql_real_escape_string($_POST['edited_answer']);
$time=time();
$sql=mysql_query("UPDATE answers SET time='$time' , answer='$edited_answer' WHERE id='$answerID'");
echo $edited_answer;
?>
chances are jQuery cannot find
submiteditanswer.phpThe path should be relative to
/Have a look in firebug, chrome developer console, or fiddler and i’m pretty sure there will be some 404 errors in there.
If you need help working out which path to use, let us all know where
submiteditanswer.phpsits in your directory structure.