• March 13, 2023
    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
        $(function() {
            $('form').on('submit', function(event) {
                var formData = $(this).serialize();
                    type: 'POST',
                    url: 'your-php-script.php',
                    data: formData,
                    success: function(response) {
                        if (response === 'error') {
                            // display error notification
                        } else {
                            // display success notification or redirect to another page
        <!-- form fields go here -->
        <button type="submit">Submit</button>

    In this example, the jQuery library is used to handle the AJAX request. The form’s submit event is intercepted and prevented from refreshing the page. The form data is serialized and sent to a PHP script using the POST method. The success function is called when the server returns a response.

    If the response is ‘error’, an error notification is displayed using the alert function. If the response is not ‘error’, a success notification is displayed or the page is redirected to another URL.

    Note that you will need to replace ‘your-php-script.php’ with the actual filename of your PHP script that contains the code you want to run.


ประหยัดเวลากว่า 100 เท่า!

สร้างเว็บไซต์ ดูแลเว็บไซต์