Note that there are some explanatory texts on larger screens.

plurals
  1. POJquery if statement not working even if the statement is true
    primarykey
    data
    text
    <p>I have a simple if statement where when i send this certain data to the database, i want the php code to send bake a code that tells javascript its ok to continue, but if the php script sends back a bad code, javascript is to now move forward and display a certain text or something.</p> <p>The php code works fine but for some reason my javascript files would not work at all.</p> <p>My javascript is suppose to ajax request to parse.php and receive the data that parse.php sends back to it, if parse.php says 200 its suppose to load in specific items.</p> <p>Here is the code for one of my systems:</p> <pre><code>$(document).ready(function(){ $("#chatForm").submit(function(){ var chatHash = $("#chatHash").val(); var body = $("#chatPoster").val(); var by = $("#userBy").val(); if(chatHash != "" &amp;&amp; body != ""){ $.post('parse.php',{chatHash: chatHash, body: body, userBy: by},function(data){ if(data == "200"){ // Right here is where its messing up $("#chatPoster").val(""); $.get('getChatMessages.php?hash=' + chatHash,function(data2){ $(".allMsgs").html(data2); }); } else { alert('Critical error'); } }); } else { alert('Error'); } }); }); </code></pre> <p>Here is the code for the parse.php page: </p> <pre><code>$chat = new ChatSystem; if(isset($_POST['chatHash']) &amp;&amp; isset($_POST['body']) &amp;&amp; isset($_POST['userBy'])){ $chat-&gt;sendMessage($_POST['userBy'],$_POST['chatHash'],$_POST['body']); } </code></pre> <p>Here is the code from the class ChatSystem that the parse.php page is referring to:</p> <pre><code> public function sendMessage($user,$hash,$body){ global $db; $date = date("Y-m-d"); $time = date("H:i:s"); $timestamp = "$date $time"; if(empty($user) == false &amp;&amp; empty($hash) == false){ $db-&gt;query("INSERT INTO chat_messages VALUES('','$user','$body','$timestamp','','0','$hash')") or die("error"); echo '200'; } } </code></pre> <p>Even though my php code works perfectly the javascript still messes up. My php code sends back 200 like i ask it to but yet the jquery messes it up</p>
    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.
 

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