简体   繁体   中英

Cannot pass values into a php function

I am having trouble passing in a value or array of values into my php script. When the submit button on the page is clicked, the following function executes:

$('#rangeSubmit').click( function (e) {
        e.preventDefault();
        $.ajax({
            type: 'POST',
            url: 'http://.../test.php',
            data: {test1:"DONE"},
            success: function(data)
            {
                $("#myDiv").html(data);
            }
    });
});

The PHP script looks like this:

<?php

    echo $argv[1]; //should return the first item in the array of values passed to the php function?
    var_dump($_SERVER['argv']);

?>  

And this script just returns "NULL" instead of the value I sent to the script. Any ideas?

$argv[1] is a reference to parameter passed from command line, like:

php page.php argument

This call page.php with "argument" as parameter than can acessible with $argv[1].

To get post variables use $_POST[$name]. In your case use:

echo $_POST['test1'];

try ;)

<?php
    echo $_POST['test1'];    
    var_dump($_POST);
?> 

use $_POST['test1']; in test.php to receive value passed through jQuery.

Dirty but may help, If your PHP install allows it, you could simply try using exec(). In your receiving script, extract the POST arguments and format them into a command string then pass that to exec() to run.

$filein =$_POST[$arg1];
$fileout =$_POST[$arg2];

$return=exec("php target.php -i $filein -o $fileout ");

USE POST

type: 'POST', --->POST REQUEST

var_dump($_POST['test1']);

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