简体   繁体   中英

Post PHP to MySql-db from JavaScript function

I have a JavaScript function (href link) that opens a modal window, and from that function/window I would like to send it to a PHP page (box.php) that has about four PHP functions; one of them is the "check_box" that checks for the other three functions. Is there a way to do that, or is it not possible/supported with the JavaScript? This is what I have:

PHP page:

<a href="javascript:openModal()" title="" style="padding-right: 10px;">LEAVE</a>

PHP code:

<?php
echo $class->box->check_box() ?>

JavaScript function:

function openModal()
    {

        $.modal({
            content: 
                    /* This where the content of the modal window goes */

            title: 'Outside the workplace',
            width: 300,
            scrolling: false,
            actions: {
                'Close' : {
                    color: 'red',
                    click: function(win) { win.closeModal(); }
                },
                'Center' : {
                    color: 'green',
                    click: function(win) { win.centerModal(true); }
                },
                'Refresh' : {
                    color: 'blue',
                    click: function(win) { win.closeModal(); }
                },
                'Abort' : {
                    color: 'orange',
                    click: function(win) { win.closeModal(); }

                }
            },

            buttons: {
                'Close': {
                    classes:    'huge blue-gradient glossy full-width',
                    click:      function(win) { win.closeModal(); }
                                    }
                                    },


            buttonsLowPadding: true
        });
    };

Create a php page that would do the insertion. Parse the parameters from the browser in that PHP and perform an insert. Then output a message. In JavaScript show the message in designated DIV -- something like this (fix to your values and pass the parameters to function):

function setToDatabase() {
    jQuery(function($) {    
        $.ajax( {           
            url : "submittosql.php?valuetosubmit=NEWVALUE",
            type : "GET",
            success : function(data) {
                document.getElementById("YOURDIV").innerHTML=data;             
            }
        });
    });
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM