Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>EDIT:</strong> There's a lot of "wrong" going on here, buddy. </p> <p>To start, you have a click function within a click function. I've fixed that. </p> <p>You also shouldn't be loading <code>.messages.php</code> to the <code>html</code> tag. Remove the body tags in <code>messages.php</code> and apply the load (i.e. <code>.load()</code>) to a container selector (as per our private chat and my code below). </p> <p>To prevent page refresh when the buttons are clicked (which would defeat the purpose of using ajax) you need to prevent the default behaviour of the button and use <code>return false</code> to prevent the page from refreshing.</p> <p>Furthermore, you have the ajax calls as variables (which aren't being called anywhere. Even if they were, it's sloppy.). This is not correct either. I've fixed this.</p> <p>Finally, I've added code to prevent multiple clicks/submits when the buttons are clicked. Essentially all I'm doing is disabling the button once it clicked and re-enabling it on the ajax success call.</p> <pre><code>$(function(){ $("#message").hide(); $.ajax({ //fill content of #messageView ... }).success(function(data){ $("#messageView").html(data); }); $('.ans_button').on('click', function() { var parts = $(this).val().split("*"); var thread = parts[0]; var subject = parts[1]; var program = parts[2]; $("#subject").val(subject); return false; }); $('#askQ').on('click', function() { // disable button on click $(this).attr("disabled", "disabled"); var question = $("#question").val(); $.ajax({ ... }).success(function(data){ if(data == "success"){ $("#message").hide(); $("#question").val(""); // why is this empty? Try using .reset() instead if you want to empty field // enable and remove disable attr $(this).removeAttr("disabled", "disabled"); } }); return false; }); $('.remove_button').on('click', function() { // disable button on click $(this).attr("disabled", "disabled"); var clicked = $(this); var parts = clicked.val().split("*"); var thread = parts[0]; var time = parts[1]; $.ajax({ ... }).success(function(data){ if(data == "success"){ $("#message").hide(); $(".container").load("messages.php"); $("#messageView").show(); // enable and remove disable attr $(this).removeAttr("disabled", "disabled"); } }); return false; }); }); </code></pre>
    singulars
    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.
    1. VO
      singulars
      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