title: How to use ajax for request the WHMCS hooks function and get my required return data?
body: <p>I read the WHMCS demo code for developing a provisioning module:</p>
  
  <p>the frontend code, <a href="https://github.com/WHMCS/sample-provisioning-module/blob/master/modules/servers/provisioningmodule/templates/overview.tpl#L259" rel="nofollow noreferrer">overview.tpl</a>.</p>
  
  <p>the backend code, <a href="https://github.com/WHMCS/sample-provisioning-module/blob/master/modules/servers/provisioningmodule/provisioningmodule.php#L744" rel="nofollow noreferrer">provisioningmodule.php</a>.</p>
  
  <p>but my code follow by the upper I want to use ajax for request, so the whole page will not re-render.</p>
  
  <hr>
  
  <p>My frontend ajax code:</p>
  
  <pre><code>    jQuery.ajax({
          url: url,
          type: "POST",
          data: {
              ...
              qn_action: "bmc"
  
          },
          dataType: 'json',
          contentType: "application/json; charset=utf-8",
          success: function (data, textStatus){
  
              console.log('ldl:',data)  // pay attention I want to console.log the return data. I wish it be the PHP return data's `templateVariables`.
              jQuery('.powercontrol').removeClass('disabled');
              jQuery(i_id).css('display', 'none');
  
              jQuery('#powerstatus-spinner').css('display', 'none'); // Status loading
          },
          error: function(jqXHR, e) {
              var msg = '';
              if(jqXHR.status==0){
                  msg = 'You are offline!!\n Please Check Your Network.';
              }else if(jqXHR.status==404){
                  msg = 'Requested URL not found.';
              }else if(jqXHR.status==500){
                  msg = 'Internal Server Error.&lt;br/&gt;'+jqXHR.responseText;
              }else if(e=='parsererror'){
                  msg = 'Error: Parsing JSON Request failed.';
              }else if(e=='timeout'){
                  msg = 'Request Time out.';
              }else {
                  msg = 'Unknow Error.&lt;br/&gt;'+x.responseText;
              }
  
              console.log('error: '+jqXHR.responseText);  // I wil get the error logs
              console.log('Error msg: '+msg);
          }
      })
  </code></pre>
  
  <p>in my backend PHP code:</p>
  
  <pre><code>function qidicatedserver_ClientArea(array $params)
  {
  
      // Determine the requested action and set service call parameters based on
      // the action.
  
      $qn_action = isset($_REQUEST['qn_action']) ? $_REQUEST['qn_action'] : '';
  
      $tblclients_id = isset($_REQUEST['tblclients_id']) ? $_REQUEST['tblclients_id'] : '';  
  
  
      $bmc_action = "";
      $server_name = "";
      $templateFile = 'templates/overview.tpl';
      $bmc_result = "";
  
  
      if($qn_action == "bmc"){
  
          $resp = array(
              'tabOverviewReplacementTemplate' =&gt; $templateFile,
              'templateVariables' =&gt; array(
                  "status"=&gt;200,
                  "data"=&gt;"my test return data"
              )
          );
  
  
  
          return $resp;
  
  
      }
  
  
      try {
          // Call the service's function based on the request action, using the
          // values provided by WHMCS in `$params`.
  
  
          return array(
              'tabOverviewReplacementTemplate' =&gt; $templateFile,
              'templateVariables' =&gt; array(
                  'data' =&gt; array(
                      "status"=&gt;"200",
                      "data" =&gt; array(
                          "bmc_result" =&gt; null
                      )
                  ),
              ),
          );
  
  
      } catch (Exception $e) {
  
          //echo $e;
          // Record the error in WHMCS's module log.
          logModuleCall(
              'qidedicatedserver',
              __FUNCTION__,
              $params,
              $e-&gt;getMessage(),
              $e-&gt;getTraceAsString()
          );
          // In an error condition, display an error page.
          return array(
              'tabOverviewReplacementTemplate' =&gt; 'templates/error.tpl',
              'templateVariables' =&gt; array(
                  'usefulErrorHelper' =&gt; $e-&gt;getMessage(),
              ),
          );
  
      }
  
  }
  </code></pre>
  
  <p>when the ajax request executed, there will get error, execute the below code:</p>
  
  <pre><code>console.log('error: '+jqXHR.responseText);  // I wil get the console log: `error: &lt;!DOCTYPE html&gt; \n&lt;html lang="en"&gt;\n&lt;head&gt;\n    &lt;meta char) ....` the html is the whole page's HTML
  console.log('Error msg: '+msg);  // the console log: `Error msg: Error: Parsing JSON Request failed.`
  </code></pre>
  
  <p>So, there must be issue in there, my problem is how to use ajax for HTTP request in WHMCS custom provisioning module, but I try get failed like upper. (I tried use form request PHP, there can get correct data, but there will re-fresh the whole page, its not my desired, I don't what the page to be refresh)</p>
  
  <p>Who can tell me how to use ajax for request WHMCS hook function and return correct data as my wish? </p>
  
  <hr>
  
  <p>You can find more introduction of WHMCS provisioningmodule<a href="https://developers.whmcs.com/provisioning-modules/" rel="nofollow noreferrer">there</a>.</p>
  
  <hr>
  
  <p><strong>EDIT-01</strong></p>
  
  <p>I tried change the return PHP code like this:</p>
  
  <pre><code>if($qn_action == "bmc"){
  
      $resp = array(
          'tabOverviewReplacementTemplate' =&gt; $templateFile,
          'templateVariables' =&gt; json_encode(array(
              "status"=&gt;200,
              "data"=&gt;"dasdas"
          ))
      );
  
  
  
      return $resp;
  
  
  }
  </code></pre>
  
  <p>but still this error.</p>