简体   繁体   English

从JavaScript函数将PHP发布到MySql-db

[英]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; 我有一个JavaScript函数(href链接)可以打开模式窗口,并且我想从该函数/窗口中将其发送到包含大约四个PHP函数的PHP页面(box.php); one of them is the "check_box" that checks for the other three functions. 其中之一是“ check_box”,用于检查其他三个功能。 Is there a way to do that, or is it not possible/supported with the JavaScript? 有没有办法做到这一点,或者JavaScript无法/不支持它? This is what I have: 这就是我所拥有的:

PHP page: PHP页面:

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

PHP code: PHP代码:

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

JavaScript function: JavaScript函数:

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. 创建一个将执行插入操作的php页面。 Parse the parameters from the browser in that PHP and perform an insert. 从该PHP的浏览器中解析参数并执行插入。 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): 在JavaScript中以指定的DIV显示消息-类似于以下内容(修复值并将参数传递给函数):

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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