Note that there are some explanatory texts on larger screens.

plurals
  1. POSubmit and Show Data using jQuery - issue
    primarykey
    data
    text
    <p>I'm trying to submit form data without refreshing the page using jQuery. I've added all the following code in correct places but the page refreshes and nothing happened, neither it echo's the success data nor it inserts any data into sql db. Here is what I'm trying to do;</p> <h2>HTML:</h2> <pre><code> $profile_comments = ' &lt;form action="#" method="post"&gt; &lt;table border="0" cellspacing="'.$theme['borderwidth'].'" cellpadding="'.$theme['tablespace'].'" class="sideboxes_tborder"&gt; &lt;tr&gt; &lt;td class="sideboxes_thead"&gt;Post Comments&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td class="sideboxes_trow"&gt; &lt;input type="text" class="textbox_comment" name="message" id="pc_message" tabindex="1" autocomplete="off" /&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td class="sideboxes_trow" align="left"&gt; &lt;input type="hidden" name="uid" value="'.$memprofile['uid'].'" /&gt; &lt;input type="hidden" name="from_uid" value="'.$mybb-&gt;user['uid'].'" /&gt; &lt;input type="submit" class="button" id="comment_submit" name="submit" value="Post Comment" tabindex="2"&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td class="sideboxes_trow"&gt;&lt;div id="show_profile_comments" style="overflow: auto; max-height: 313px;"&gt;&lt;/div&gt;&lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/form&gt;'; </code></pre> <h2>jQuery:</h2> <pre><code>jQuery.noConflict(); jQuery(document).ready(function($) { $("#comment_submit").click(function() { var message = $( "#pc_message" ).val(), if (message == '') { alert( "Message is missing!!" ); return; } $.ajax( { type : "post", dataType: "html", url : "pro_profile.php?action=do_comment", data : "message=" + message, success : function(response) { $('#show_profile_comments').html(response); } document.getElementById('pc_message').value = ''; document.getElementById('pc_message').focus(); if (response.error) { alert(response.error); } }); }); }); </code></pre> <h2>PHP:</h2> <pre><code>if ($_POST['action'] == "do_comment") { $uid = intval($mybb-&gt;input['uid']); $insert_array = array( "uid" =&gt; $uid, "from_uid" =&gt; intval($mybb-&gt;input['from_uid']), "approved" =&gt; '1', "message" =&gt; $db-&gt;escape_string($mybb-&gt;input['message']), "dateline" =&gt; TIME_NOW ); $db-&gt;insert_query("pp_comments", $insert_array); $query = $db-&gt;simple_select("pp_comments", "*", "uid='{$uid}'"); $c = $db-&gt;fetch_array($query); echo $c['message']; } </code></pre> <p>Please help!</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.
    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