cools2 Posted October 19, 2017 Share Posted October 19, 2017 I create a file ajax.php in /includes/hooks When I click on the button, I send ajax request to the file ajax.php, there I launch the localAPI function, but it does not work, what am I doing wrong? How can i create invoice by ajax? Link to comment Share on other sites More sharing options...
wtools Posted October 20, 2017 Share Posted October 20, 2017 Actually you can upload hook files to the folder /includes/hooks. Can you paste here the code added to the file ajax.php? Also where you wrote the jQuery code to call the API asynchronously? Link to comment Share on other sites More sharing options...
cools2 Posted October 20, 2017 Author Share Posted October 20, 2017 I have main page home-page.tpl with button ( just for test ). Its look like this: $('.submit').on('click', function () { jQuery.post('{$systemurl}includes/hooks/ajax.php', {action:'createInvoice'}, function(data) { console.log(data); }); });On the file ajax.php: <?php use Illuminate\Database\Capsule\Manager as Capsule; if($_POST['action'] == 'createInvoice'){ function getAdminUserName() { $adminData = Capsule::table('tbladmins') ->where('disabled', '=', 0) ->first(); if (!empty($adminData)) return $adminData->username; else die('No admin exist. Why So?'); } $command = 'CreateInvoice'; $postData = array( 'userid' => '1', 'status' => 'Unpaid', ); $adminUsername = getAdminUserName(); $results = localAPI($command, $postData, $adminUsername); print_r($results); die(); } answer is : 500 (Internal Server Error) Link to comment Share on other sites More sharing options...
wtools Posted October 22, 2017 Share Posted October 22, 2017 Hi, Actually it's better to place the file in root directory. You can place code with some action in the folder /includes/hooks. . But the code you wrote in teh ajax.php don't have any hook. Place the file in the WHMCS root directory. Follow the link https://developers.whmcs.com/advanced/creating-pages/ Link to comment Share on other sites More sharing options...
Recommended Posts