在POST模式下发送XMLHttpReguest参数后,ajax / php将其保存到哪个变量/数组?

时间:2018-12-16 10:54:39

标签: javascript php ajax

我收到错误“未定义的索引...”。我在POST模式下通过XMLHttpRequest发送带有参数的请求。我不知道如何通过目标php脚本读取发送的参数。我有这样的代码:

class Pipe {
    constructor(value) {
        this.value = value;
    }
    then(f) {
        return new Pipe(f(this.value));
    }
}
    
const pipe = value => new Pipe(value);
    
// Example

const double = x => 2 * x;
    
pipe(42).then(double).then(console.log); // 84

const result = pipe(42).then(double).then(double).value;
console.log(result); // 168

在“ install_mom.php”中,我有这样一行(来自其他许多行)

#include <stdio.h>
#include <string.h>

void print_formated(const char *text, size_t size)
{
    char *token;
    char *rwstring = malloc(strlen(text) + 1);
    size_t len = 0;

    if(rwstring)
    {
        strcpy(rwstring, text);
        token = strtok(rwstring, " ");
        while(token)
        {
            if(len + strlen(token)> size)
            {
                printf("\n");
                len = 0;
            }
            printf("%s ", token);
            len += strlen(token) + 1;
            token = strtok(NULL, " ");
        }
        free(rwstring);
    }
}


int main()
{
    print_formated("Lorem      ipsum dolor sit amet, consectetuer adipiscing elit. Integer metus", 20);

    return 0;
}

当我运行脚本时,它告诉我在function sendXML(location, strParams, redirectToOnSuccess) { var xmlhttp; if (window.XMLHttpRequest) xmlhttp = new XMLHttpRequest(); else xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); xmlhttp.onreadystatechange = function () { if (this.readyState == 4 && this.status == 200) { if (this.responseText == "OK") { alert("Operacja zakończona sukcesem"); window.open("index.php", "_self"); } else alert("Coś poszło nie tak: " + this.responseText); } } xmlhttp.open("POST", location, true); xmlhttp.send(strParams); } // (...) $str = "Database and username do not exist. Create new?\\n\\Username: " . $_POST["usr"] . "\\DB name: " . $_POST["db"] . "\\Host: " . $_POST["addr"] . "\\n\\nIf info is correct, press OK."; $strParams = "'usrRoot=" . $_POST["usrRoot"] . "&passRoot=" . $_POST["passRoot"] . "&usr=" . $_POST["usr"] . "&pass=" . $_POST["pass1"] . "&db=" . $_POST["db"] . "&addr=" . $_POST["addr"] . "'"; //echo $strParams; echo "<script>if (confirm('" . $str . "', 'Czy dane się zgadzają?')){sendXML('install_mom.php', " . $strParams . ", 'index.php');}</script>"; 中,$connection = new mysqli($_REQUEST["addr"], $_REQUEST["usrRoot"], $_REQUEST["passRoot"], ""); 是未定义的。我在做什么错了?

谢谢迈克。

0 个答案:

没有答案