Theme Customizer

jQuery PHP AJAX Plugin

The $.php() component allows you to perform server-side AJAX requests that automatically execute jQuery/wrapper queries, mutate DOM contents, apply styles, and run callback commands returned directly by your PHP scripts.

Live Server Demo

Enter your name below and click the button to trigger a $.php() request to a server-side PHP endpoint. The server will respond with JSON commands to dynamically build, style, and alert the output box below.

(Output empty. Click button to load server response)

Usage Code Example

// Triggering AJAX request using the jQuery PHP component syntax
$('#btn-trigger-ajax').click(function() {
    const nameVal = $('#greet-name').val();
    
    // Sends a POST request, automatically processing DOM queries returned in the JSON payload
    $.php('data/php_endpoint.php', { 
        action: 'greet', 
        name: nameVal 
    });
});

PHP Server-Side Payload Format

Your PHP script must output JSON content defining queries (q) and custom messages/actions (a):

<?php
header('Content-Type: application/json');

echo json_encode([
    'q' => [
        [
            's' => '#ajax-output',           // Element selector
            'm' => ['html', 'css'],           // Methods to execute in chain
            'a' => [                          // Arguments corresponding to each method
                'Hello <strong>World</strong>!', 
                ['color' => '#0078d7', 'background-color' => '#f0f4f8']
            ]
        ]
    ],
    'a' => [
        'addMessage' => [
            [
                'msg' => 'Operation finished successfully!',
                'callback' => 'defaultCallBack',
                'params' => new stdClass()
            ]
        ]
    ]
]);