Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/429.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 带参数的Ajax/PHP上传(再次…)_Javascript_Php_Ajax - Fatal编程技术网

Javascript 带参数的Ajax/PHP上传(再次…)

Javascript 带参数的Ajax/PHP上传(再次…),javascript,php,ajax,Javascript,Php,Ajax,我已经阅读了很多关于这个的问题和答案,但我似乎无法让它们中的任何一个起作用。为了节省大脑空间,我已经把它缩小到尽可能小的尺寸 index.html: <html> <head></head> <body> <script type="text/javascript"> var ajax = new XMLHttpRequest(); someData = '9876324iuygweighfds'; ajax.o

我已经阅读了很多关于这个的问题和答案,但我似乎无法让它们中的任何一个起作用。为了节省大脑空间,我已经把它缩小到尽可能小的尺寸

index.html:

<html>
<head></head>
<body>
<script type="text/javascript">
    var ajax = new XMLHttpRequest();
    someData = '9876324iuygweighfds';
    ajax.open("POST", 'http://www.server.com/ajaxTest.php?a=123', false);
    ajax.setRequestHeader("Content-type",'application/upload');
    ajax.send(someData); 
    document.write(ajax.responseText);
</script>
</body>
</html>

var ajax=new-XMLHttpRequest();
someData='9876324IUYGFDS';
打开(“POST”http://www.server.com/ajaxTest.php?a=123",假),;
setRequestHeader(“内容类型”,“应用程序/上传”);
发送(someData);
document.write(ajax.responseText);
ajaxTest.php:

<?php
$a = $_POST['a'];
echo "This is the server. <br>".$a."<br>";
?>

我得到的只是:

这是服务器


实际目标是一次性发送从画布收集的图像数据和一些参数。快把我逼疯了。我可能错过了一些简单的东西,所以我向你表示感谢和道歉-这是漫长的一天:-)

你需要设置
someData='a=123'如果您想将其作为POST变量访问


或者,您可以将PHP更改为
$a=$\u GET['a']

您只需要更改自己代码的这一部分

<?php
    $a = $_GET['a']; // HEREEEEEE \o
    echo "This is the server. <br>".$a."<br>";
?>


Try
$a=$\u GET['a']我从来不知道POST和GET在接收脚本上是可互换的!只是快速浏览了一些教程,他们从未提及过。非常感谢