简体   繁体   中英

javascript function passes only one specific parameter

I built this function in my html page:

<script type = "text/javascript">
    function set() {
        var type = 'test';
        var status = 0;
        var id = 2;
        $.post("sys/class/buttonHandler.php"), { status: status};
    }
</script>

that is triggered by this button:

<button type="button" onclick="set()" class="btn">Press here</button>

to reach this buttonHandler.php:

<?php

    require 'class.global.php';

    $type = 'test';
    $status = $_POST['status'];
    $id = 2;

    set($type, $status, $id);

?>

that correctly executes this function in the class.global.php:

function set($type, $status, $id)
{
    $result = mysql_query("UPDATE users SET $type = '$status' WHERE id = '$id'");
}

The problem is when I try to change the parameter that the javascript function passes or when I try to add the other two parameters, like this:

    <script type = "text/javascript">
                function set_profile() {
                    var type = 'test';
                    var status = 0;
                    var id = 2;
                    $.post("sys/class/admobButtonHandler.php"), { status: status, type: type, id: id};
                }
            </script>

<?php

require 'class.global.php';

$type = $_POST['type'];
$status = $_POST['status'];
$id = $_POST['id'];

setProfile($type, $status, $id);

?>

Nothing works anymore.. Is there any other way that I can make this work? Thanks

Take a look at the jQuery docs for the post() function. http://api.jquery.com/jquery.post/ . You've got your syntax all wrong... It should be:

$.post("/sys/class/admobButtonHandler.php", {status: status, type: type, id: id});

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