- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
尝试使用一些变量和长 JSON 发出简单的 xhr 请求。当我var_dump($_POST)
、var_dump($_REQUEST)
或var_dump(file_get_contents('php://input'))
时,我明白了:
array(1) {
["------WebKitFormBoundarySaVZDjpQjjwsAOHs
Content-Disposition:_form-data;_name"]=>
string(5725) ""document_id"
608
------WebKitFormBoundarySaVZDjpQjjwsAOHs
Content-Disposition: form-data; name="project_id"
2
------WebKitFormBoundarySaVZDjpQjjwsAOHs
Content-Disposition: form-data; name="user_id"
42
------WebKitFormBoundarySaVZDjpQjjwsAOHs
Content-Disposition: form-data; name="stage"
1
------WebKitFormBoundarySaVZDjpQjjwsAOHs
Content-Disposition: form-data; name="show_save_button"
1
------WebKitFormBoundarySaVZDjpQjjwsAOHs
Content-Disposition: form-data; name="id_user_associatedDoc"
42
------WebKitFormBoundarySaVZDjpQjjwsAOHs
Content-Disposition: form-data; name="annotation"
{"nodes":[{"id":0,"x":67,"y":101,"text":"ng heard. Engaged at village at am equally proceed. Settle nay length almost ham direct extent. Agreement for listening remainder get attention law acuteness","width":229,"height":100,"type":"I","color":"b","scheme":0,"visible":true},{"id":1,"x":325,"y":59,"text":"Entire any had depend and figure winter. Change stairs and men likely wisdom new happen piqued six. Now taken him timed sex world get. Enjoyed married an feeling delight pursuit as offered. As admire roused length likely played pretty to no. Means had joy miles her merry solid order. Entire any had depend and figure winter. Change stairs and men likely wisdom new happen piqued six. Now taken him timed sex world get. Enjoyed married an feeling delight pursuit as offered. As admire roused length likely played pretty to no. Means had joy miles her merry solid order. Entire any had depend and figure winter. Change stairs and men likely wisdom new happen piqued six. Now taken him timed sex world get. Enjoyed married an feeling delight pursuit as offered. As admire roused length likely played pretty to no. Means had joy miles her merry solid order. Entire any had depend and figure winter. Change stairs and men likely wisdom new happen piqued six. Now taken him timed sex world get. Enjoyed married an feeling delight pursuit as offered. As admire roused length likely played pretty to no. Means had joy miles her merry solid order. Entire any had depend and figure winter. Change stairs and men likely wisdom new happen piqued six. Now taken him timed sex world get. Enjoyed married an feeling delight pursuit as offered. As admire roused length likely played pretty to no. Means had joy miles her merry solid order. Entire any had depend and figure winter. Change stairs and men likely wisdom new happen piqued six. Now taken him timed sex world get. Enjoyed married an feeling delight pursuit as offered. As admire roused length likely played pretty to no. Means had joy miles her merry solid order. Entire any had depend and figure winter. Change stairs and men likely wisdom new happen piqued six. Now taken him timed sex world get. Enjoyed married an feeling delight pursuit as offered. As admire roused length likely played pretty to no. Means had joy miles her merry solid order. Entire any had depend and figure winter. Change stairs and men likely wisdom new happen piqued six. Now taken him timed sex world get. Enjoyed married an feeling delight pursuit as offered. As admire roused length likely played pretty to no. Means had joy miles her merry solid order. Entire any had depend and figure winter. Change stairs and men likely wisdom new happen piqued six. Now taken him timed sex world get. Enjoyed married an feeling delight pursuit as offered. As admire roused length likely played pretty to no. Means had joy miles her merry solid order. Entire any had depend and figure winter. Change stairs and men likely wisdom new happen piqued six. Now taken him timed sex world get. Enjoyed married an feeling delight pursuit as offered. As admire roused length likely played pretty to no. Means had joy miles her merry solid order. Entire any had depend and figure winter. Change stairs and men likely wisdom new happen piqued six. Now taken him timed sex world get. Enjoyed married an feeling delight pursuit as offered. As admire roused length likely played pretty to no. Means had joy miles her merry solid order. Entire any had depend and figure winter. Change stairs and men likely wisdom new happen piqued six. Now taken him timed sex world get. Enjoyed married an feeling delight pursuit as offered. As admire roused length likely played pretty to no. Means had joy miles her merry solid order. Entire any had depend and figure winter. Change stairs and men likely wisdom new happen piqued six. Now taken him timed sex world get. Enjoyed married an feeling delight pursuit as offered. As admire roused length likely played pretty to no. Means had joy miles her merry solid order. Entire any had depend and figure winter. Change stairs and men likely wisdom new happen piqued six. Now taken him timed sex world get. Enjoyed married an feeling delight pursuit as offered. As admire roused length likely played pretty to no. Means had joy miles her merry solid order. Entire any had depend and figure winter. Change stairs and men likely wisdom new happen piqued six. Now taken him timed sex world get. Enjoyed married an feeling delight pursuit as offered. As admire roused length likely played pretty to no. Means had joy miles her merry solid order. Entire any had depend and figure winter. Change stairs and men likely wisdom new happen piqued six. Now taken him timed sex world get. Enjoyed married an feeling delight pursuit as offered. As admire roused length likely played pretty to no. Means had joy miles her merry solid order. ","width":200,"height":2420,"type":"I","color":"b","scheme":0,"visible":true}],"edges":[],"metadata":{"documentId":"608","projectId":"2","ranges":[[554,760],[17,302]],"idUserAssociatedDoc":"42"}}
------WebKitFormBoundarySaVZDjpQjjwsAOHs--
"
}
但是一旦我尝试访问这些字段,我就会得到 NULL :(
我尝试了不同的内容类型(multipart/form-data、application/x-www-form-urlencoded 或无)
xhr:
var xhr = new XMLHttpRequest();
xhr.open('POST', resultsURL, true);
xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
xhr.onload = function () {
// do something to response
console.log(this.responseText);
};
var dataSave = new FormData();
dataSave.append('document_id', documentId);
dataSave.append('project_id', projectId);
dataSave.append('user_id', userId);
dataSave.append('stage', stage);
dataSave.append('show_save_button', showSaveButton);
dataSave.append('id_user_associatedDoc', idUserAssociatedDoc);
dataSave.append('annotation', JSON.stringify(json));
xhr.onreadystatechange = function() {
switch(xhr.readyState) {
case XMLHttpRequest.OPENED:
case XMLHttpRequest.LOADING:
if(callbackLoading)
callbackLoading();
break;
case XMLHttpRequest.DONE:
console.log("XMLHttpReques.responseText:");
console.log(xhr.responseText);
break;
}
}
xhr.send(dataSave);
在结果URL php上:
$docId = $_REQUEST['document_id'];
echo var_dump($docId); //returns NULL
这不是应该行得通吗?你知道我可能做错了什么吗?
最佳答案
多部分/表单数据
new FromData
是带有边界 ( https://www.w3.org/Protocols/rfc1341/7_2_Multipart.html ) 的 multipart/form-data。您不应设置任何内容类型 header 。 header 将由浏览器设置。您可以使用 $_POST
或 $_REQUEST
访问数据。
application/x-www-form-urlencoded
如果您使用 application/x-www-form-urlencoded,则必须发送编码后的日期 url。
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
// ...
function encodeForm(dataSave) {
bar r = [];
dataSave.forEach((v,k) => {
r.push(encodeURIComponent(k) + '=' + encodeURIComponent(v));
});
return r.join('&');
}
xhr.send(encodeForm(dataSave));
您可以使用 $_POST 或 $_REQUEST 访问数据
application/x-www-form-urlencoded 的开销较小。
关于javascript - 无法访问 $_POST 或 $_REQUEST 或 'php://input' - 全部不为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55557982/
下面的代码可以从数据库中删除行,但不能插入。这是为什么? 最佳答案 试试这个: mysql_connect("localhost","formuser","password") or die(mys
在 /app/models/review.rb ,我有一种方法,旨在从 review#print 的输出创建 PDF行动。还旨在捕获我的整个打印样式表并在我处于生产模式时将其内联到标题中: def c
我有一个搜索表单,我想将搜索词 $_REQUEST 作为一个数组,这样我就可以列出每个搜索词,将每个词包装在一个跨度中以进行样式设置。我怎么做? 编辑:这是请求的代码。 更新:谢谢大家的回答
PHP 超全局变量 PHP 具有可以在脚本的任何范围内访问的全局变量。其中三个变量($_GET、$_POST、$_COOKIE)存储在第四个变量($_REQUEST >). $_GET An asso
我对 php 中的 $_REQUEST 全局变量有疑问。当您使用相同的变量名提交了一个 get 和一个 post 时,php 会为它们中的任何一个分配优先级吗? IE。如果我将 $_POST['var
考虑以下代码片段: 图表 A: $_REQUEST = json_decode(stripslashes(json_encode($_REQUEST, JSON_HEX_APOS)), true);
我有这个代码。 $message = ""; if($_REQUEST['msg'] == "new"){ $message = "New User has been added succes
我正在开发 ZEND 框架,这对我来说是新的,AJAX 也是如此。我尝试了很多例子,但没有一个起作用。 请告诉我这段代码是错误的。 home.phtml
我想将一个变量传递给我的 Controller ,并且无论其请求方法(POST 或 GET)如何,我都需要获取它的值,相当于 $_REQUEST['myvar'],我该怎么做? 最佳答案 要获取作为路
我正在尝试从 URL 向我的 facebook 应用程序传递一些变量,即像 facebook 想要的那样使用 GET 变量 app_data 。 在某些时候,我已经停止获取 $_REQUEST 的 [
我有一个与外部 API 交互的应用程序。当远程服务发布包含特定状态的请求时,我需要通过外部 URL 将该帖子的全部内容重新发送到不同的应用程序。 是否可以获取整个 $_REQUEST 并将其重新发布到
首先我要说的是我并不真正了解 PHP...我正在为一个项目摆弄它。 我正在将数据从 Java 程序发布到我的 .php 文件。我当前的问题是,现在我希望我的 Java 函数将数据发布到 PHP 文件,
我无法使用 PHP 获取文本字段 new_list_id 的值。这是我的代码: New Input 101 102 var selectm
我有一个将数据插入 mySQL 的表单。效果很好。 提交后,我有一个显示“part_no”的成功页面。我还需要显示“add_qty”。 如何更改我的帖子脚本以在成功页面上显示两个字段数据? 这是我的代
运动选项的类型是从我拥有所有运动类型的数据库中选择的。Type_sport 包含运动的名称。一切都很好,数据库中的所有运动都显示在选项列表中。但是,当选项来自数据库时,我如何 $_REQUEST 用户
我在 html 文件中有表单,它是文件正文 function f() { var name = document.getElement
我有一些像这样的简单代码: "; echo $_COOKIE['user']; ?> 这是结果: Notice: Undefined index: user in D:\interpub\wwwroo
我最近在 PHP 脚本中遇到了这一行: $_REQUEST['start_date']=$date; 以任何方式为 super 全局 $_REQUEST 变量赋值是否允许或有用?如果有 $_COOKI
$p = (isset($_REQUEST["p"])?$_REQUEST["p"]:""); 这是我通常在我的 php 代码中使用的公共(public)行。我总是假设是否有更好(更小和更快)的方式来
最近我遇到了一些与 PHP 相关的流行答案,建议使用超全局 $_REQUEST,我认为这是代码味道,因为它让我想起了 register_globals. 您能否提供一个很好的解释/证据来说明为什么 $
我是一名优秀的程序员,十分优秀!