title: How to handle error from php handler file
body: <p>If there is an error in the js/send_to_telegram.php file, then the error script will work. How to do it?</p>
  <pre><code>jQuery(&quot;form&quot;).submit(function () {
          var form_data = jQuery(this).serialize();
          jQuery.ajax({
              type: &quot;POST&quot;,
              url: &quot;js/send_to_telegram.php&quot;,
              data: form_data,
              success: function (result) {
                  donemodal.style.display = &quot;block&quot;;
              },
              error: function (jqXHR, exception) {
                  errormodal.style.display = &quot;block&quot;;
              }
          });
      });
  </code></pre>
  <p>in js/send_to_telegram.php the following code:</p>
  <pre><code>$token = &quot;5306003979:AAEPK2NhlxW&quot;;
  $chat_id = &quot;497358&quot;;
  $txt = htmlspecialchars($_POST[&quot;text&quot;]);
  
  $sendToTelegram = fopen(&quot;https://api.telegram.org/bot{$token}/sendMessage?chat_id={$chat_id}&amp;parse_mode=html&amp;text={$txt}&quot;,&quot;r&quot;);
  </code></pre>
  <p>Now, even if you enter the wrong token in $sendToTelegram, it returns success. How to get error if token is wrong?</p>