我无法通过将其作为xmlhttp数据发送到PHP脚本来发布字符串。 我真正想要做的是从另一个变量读取我现在作为硬编码字符串发送的数据。
我现在拥有以下代码:
xmlhttp.open("POST", "test.php", true);
xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlhttp.send("name=testname");
此帖子请求执行良好,PHP脚本接收name参数的内容($ stringData = $ _POST [" name"]);
我正在尝试更换' testname'包含变量动态内容的字符串。所以
VARIABLE= "someContentNotHardCoded";
xmlhttp.send("name="+ VARIABLE);
但这似乎不起作用。是否有可能在这里尝试添加/替换' testname'从变量加载动态内容的字符串?
答案 0 :(得分:-1)
这是可能的,但有了这些改动: 变量应以$符号开头,并使用。签名:
$variable = "someContentNotHardCoded";
xmlhttp.send("name=".$variable);