This topic is locked

Native PHPRunner ajax functions to send requests to endpoint

1/9/2026 12:40:15
PHPRunner General questions
C
Chris Whitehead author

I’m not sure whether this is possible, but I thought I’d ask in case someone has done something similar.

I have a small chat / messaging feature with AJAX endpoints for adding new messages, as well as marking and pinning messages. At the moment this is handled via a custom PHP file loaded in a popup modal. I was wondering whether PHPRunner provides any native AJAX functionality that could be used instead.

I can see there’s a JavaScript API and some AJAX helper-related features, but I can’t find anything that allows you to send a general AJAX request. I did consider using a tri-part custom button to submit data, which would work for adding a single message, but pinning messages would require each message to have its own custom button, which doesn’t feel ideal.

ChatGPT 1/9/2026

PHPRunner does provide some capabilities for working with AJAX, but it may not offer the full flexibility you’re looking for when it comes to custom AJAX requests for a chat or messaging feature. However, there are ways to implement AJAX functionality within PHPRunner that can help you achieve your goals.

Here are some suggestions:

  1. Use the Built-in AJAX Features:
    PHPRunner has built-in support for AJAX for certain operations, such as adding, editing, and deleting records. You can leverage these features for basic CRUD operations, which might help with adding new messages. Check the “Use AJAX” option in the event settings when you create your pages.


  2. Custom JavaScript and AJAX Calls:
    You can add custom JavaScript to your PHPRunner project. You can create your own AJAX calls using jQuery.ajax() or the native fetch() API. This allows you to send requests to your PHP scripts for adding messages, pinning, and marking messages without needing to create separate buttons for each message.

    Here’s a basic example of how you can implement this in your custom JavaScript:

    function sendMessage(messageContent) {
    $.ajax({
    url: 'your_custom_php_file.php',
    type: 'POST',
    data: { message: messageContent },
    success: function(response) {
    // Handle success (e.g., update the chat display)
    },
    error: function(xhr, status, error) {
    // Handle error
    }
    });
    }

    function pinMessage(messageId) {
    $.ajax({
    url: 'your_custom_php_file.php',
    type: 'POST',
    data: { action: 'pin', id: messageId },
    success: function(response) {
    // Handle success (e.g., update message state)
    },
    error: function(xhr, status, error) {
    // Handle error
    }
    });
    }

  3. Using Event Handlers:
    You can utilize the event handlers provided in PHPRunner to trigger your custom JavaScript functions. For instance, you can add a custom button in your message list and bind an event to it to call your AJAX functions.


  4. Modal Popups:
    Since you are already using a modal for your chat feature, consider keeping that structure but using custom AJAX calls within the modal to handle message operations. You could maintain a single modal for sending and pinning messages, leveraging the same AJAX function for different actions based on user input.


  5. External Scripts:
    If your AJAX functionality is complex, consider creating a separate PHP API that handles all your messaging actions. This way, your front-end JavaScript can interact with this API without needing multiple custom PHP files for different actions.



Conclusion

While PHPRunner does not provide a direct way to send arbitrary AJAX requests natively, you can achieve your functionality by using custom JavaScript with AJAX calls. This approach allows you to manage your messaging feature efficiently without cluttering your interface with too many buttons. Remember to handle responses appropriately and update your UI as needed to reflect changes in real-time.

C
Chris Whitehead author 1/9/2026

Thank you Chatty, I have functions which do something similar, I was just wondering if there's any native PHPrunner functions .

For example like accessing the server event of any button on the page from a JS driven event. say something like this (I asked ChatGPT).

Runner.runButton(
pageid, // REQUIRED
"chat_ajax", // Button name
{
action: "test",
foo: "bar"
},
function(resp) {
console.log(resp);
}
);

and in response.

$params = $this->getParams();

echo json_encode([
"ok" => true,
"params" => $params
]);
exit;
Sergey Kornilov admin 1/9/2026

I don't think with any API for this as "accessing a server part of a button" is not a common request. While you can mimic what PHPRunner does when the button is clicked, it will be much easier to do your own thing.

C
Chris Whitehead author 1/10/2026

Cheers Sergey,

It was just me thinking and wondered if there's any native PHPRunner methods I can use within a Runner.displayPopup to send ajax data to the server event or other server events within other button..

Sergey Kornilov admin 1/10/2026

I guess you need to rethinkg your approach. I understand that it is convenient to think about buttons as functions but this would be a poor application design. Buttons and other server side events run in a certain context, have specific parameters etc, If you need to reuse a piece of code - you need to create a function and call it from both button's code and from your own AJAX request.