Note that there are some explanatory texts on larger screens.

plurals
  1. POcheck if php-clause true or false using jquery
    text
    copied!<p>hey there i have this script´s:</p> <pre><code>$.ajax({ url: "checkAvailability.php", type: 'POST', dataType: "json", data: 'username=' + $(this).data('id'), success: function(data) { if (result == 1) { $("#select-err").text(data.error ? data.error : ""); } else { $("#select-err").text(data.error ? data.error : ""); } } }); </code></pre> <p>in checkAvailability.php:</p> <pre><code>$availabilityChecker = new AvailabilityChecker($config); if($availabilityChecker-&gt;check_availability($_POST['username'])) { echo json_encode(array("error" =&gt; "is ok")); $result = 1; } else { echo json_encode(array("error" =&gt; "Wrong chose")); $result = 0; } </code></pre> <p>while testing i found out that this is not the correct way to check if a php-clause is true or false, so i need your help...could anyone show me how to check this via jquery? greetings and thanks!</p> <p>UPDATE: i changed to:</p> <pre><code>$availabilityChecker = new AvailabilityChecker($config); if($availabilityChecker-&gt;check_availability($_POST['username'])) { echo 1; } else { echo 0; } </code></pre> <p>and:</p> <pre><code>$.ajax({ url: "checkAvailability.php", type: 'POST', dataType: "json", data: 'username=' + $(this).data('id'), success: function(data){ if(data == 1){ $("#select-err").text(data.error ? data.error : "is ok"); } else{ $("#select-err").text(data.error ? data.error : "not ok"); } } }); </code></pre> <p>it works, BUT: if data == 1, on my page "1" is displayed, why and how can i fix this?</p>
 

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