Note that there are some explanatory texts on larger screens.

plurals
  1. POAjax Jquery Comments Page
    primarykey
    data
    text
    <p>I've looked at many posts here on SO and I thought that what I have would work in terms of sending form data using AJAX without refreshing the page. Unfortunately it's not working and I'm at a loss to see what it going wrong so here is my code:</p> <p>profile.php</p> <pre><code>&lt;script&gt; $(function () { $('form#commentform').on('commentsubmit', function(e) { $.ajax({ type: 'post', url: 'insertcomment.php', data: $(this).serialize(), success: function () { alert('MUST ALERT TO DETERMINE SUCCESS PAGE'); $("#comment").val(''); } }); e.preventDefault(); }); }); &lt;/script&gt; &lt;form id='commentform' method='post'&gt; &lt;textarea class='comment' id='comment'&gt;&lt;/textarea&gt; &lt;input type='hidden' name='activityid' value='$activityid'&gt; //$activityid is the ID of the status so the database knows what status ID to connect the comment with &lt;input type='submit' name='commentsubmit' value='Comment'&gt; &lt;/form&gt; </code></pre> <p>insertcomment.php</p> <pre><code>&lt;?php include 'header.php'; $activityid=htmlspecialchars($_POST['activityid'], ENT_QUOTES); $comment=htmlspecialchars($_POST['comment'], ENT_QUOTES); $commentsql=$conn-&gt;prepare('INSERT INTO wp_comments (user_id, activity_id, comment, datetime) VALUES (:userid, :friendid, :comment, CURRENT_TIMESTAMP)'); $commentsql-&gt;bindParam(':userid', $_SESSION['uid']); $commentsql-&gt;bindParam(':activityid', $activityid); $commentsql-&gt;bindParam(':comment', $comment); $commentsql-&gt;execute(); include 'bottom.php'; ?&gt; </code></pre> <p>The end result hopefully is that the comment gets inserted into the database without refreshing the page and then the text area is reset.</p> <p>As of right now when I click the comment submit button it refreshes the page.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload