Note that there are some explanatory texts on larger screens.

plurals
  1. POe.keyCode is not working in jquery
    primarykey
    data
    text
    <p>Hi I'm making commenting system using jquery and php. The thing is the e.keycode is not working...it is directly taking to the php page but I just want it to just send the data and remain in the page...(I'm using handlebars for templating) following is my code:</p> <p>the markup:</p> <pre><code>&lt;form id="insert_comments" action="insert_comments.php" method="POST"&gt; //the comment &lt;input type="text" name="comment" id="comment" placeholder="add your comment.." /&gt; //the post_id where the comment is passed &lt;input type="hidden" id="post_id" name="post_id" value="{{post_id}}"/&gt; //this is the $_GET['user'] variable here I'm displaying a number //so I'm using get_user function to get the full name using the number &lt;input type="hidden" name="to_user" id="to_user" value="&lt;?php echo get_user('roll_no',"$get_user",'fullname','users'); ?&gt;"/&gt; &lt;/form&gt; </code></pre> <p>the jquery:</p> <pre><code>//the object named as comment var comment = { //the function which handles all operations which accepts config methods as parameters init: function(config){ this.config = config; //trigger the events methos in this object this.events(); }, //the event function events: function(){ //the area of the comment text box this.config.textarea.keyup(function(e){ //if the key is enter key if(e.keyCode==13 ){ //here we are preventing default of that area so it won't jump to other page but it's not working!! e.preventDefault(); //this var is created for using the this word var self = comment; //the ajax call $.ajax({ url: self.config.url, type: "POST", data: self.config.form.serialize(), success: function(data){ //on success just console.logging the result... console.log(data); } }); //end of ajax } //end of if statement }); //end of the event keyup } //end of this method };//end of this object comment.init({ form: $("#insert_comments"),\ textarea: $("#comment"), url: "insert_comments.php" }); </code></pre>
    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