php提交字段打印,在隱藏的表單字段中提交的JSON編碼的PHP數組 - 在提交表單的頁面中打印時會產生奇怪的輸出...
In the following SSCCE, in index.php, a button is printed. When you click this button, a form is submitted (in the click listener of the button in JS) which contains one hidden input field, the value of which is json_encode($anArray).
在下面的SSCCE中,在index.php中,打印一個按鈕。當您單擊此按鈕時,將提交一個表單(在JS中按鈕的單擊偵聽器中),其中包含一個隱藏的輸入字段,其值為json_encode($ anArray)。
The action attribute of the form has a value of test.php, so the form is submitted to test.php.
表單的action屬性值為test.php,因此表單提交給test.php。
In test.php, I print out the contents of $_POST, but I get this weird output:
在test.php中,我打印出$ _POST的內容,但是我得到了這個奇怪的輸出:
Array ( [something] => { )
數組([something] => {)
The question is why, and what do I do to fix it?
問題是為什么,我該怎么做才能解決它?
The second question is that, at the moment test.php opens in new tab, can I force it to rather open in a new window?
第二個問題是,目前test.php在新標簽中打開,我可以強制它在新窗口中打開嗎?
test.php:
if (isset($_POST["something"])) {
print_r( $_POST );
} else {
echo '$_POST["something"] is not set.';
}
?>
script.js:
$(document).ready(function() {
$("#someButton").click(function() {
window.open('', 'TheWindow'); document.getElementById('TheForm').submit(); });
});
index.php:
$dataToPass = array(
"A" => array(
1 => array(
"id" => 1,
"secondId" => 2,
"thirdId" => 3
)
),
"B" => array(
1 => array(
"id" => 4,
"secondId" => 5,
"thirdId" => 6
),
2 => array(
"id" => 7,
"secondId" => 8,
"thirdId" => 9
)
),
"C" => array(
1 => array(
"id" => 10,
"secondId" => 11,
"thirdId" => 12
)
)
);
?>
print_r(json_encode($dataToPass));echo "
";//check
?>
Click me
1 个解决方案
#1
2
Your tag should look like this:
您的標記應如下所示:
Note the use of single-quote characters instead of double-quotes for the value attribute. JSON strings contain double-quote characters; your HTML is reaching the browser looking like this:
請注意,對於value屬性,使用單引號字符而不是雙引號。 JSON字符串包含雙引號字符;你的HTML到達瀏覽器看起來像這樣:
That's why all you get for the value is {.
這就是為什么你得到的價值是{。
Really, to be certain that things will work (the JSON could contain a single-quote too), you should use an HTML encoder to transform any embedded single- or double-quote characters into HTML entities. That way you're guaranteed that the final HTML will not confuse the HTML parser.
實際上,為了確保事情可行(JSON也可以包含單引號),您應該使用HTML編碼器將任何嵌入的單引號或雙引號字符轉換為HTML實體。這樣,您可以保證最終的HTML不會混淆HTML解析器。
php提交字段打印,在隱藏的表單字段中提交的JSON編碼的PHP數組 - 在提交表單的頁面中打印時會產生奇怪的輸出...相关推荐
- [快速] 一行指令暫時隱藏 Mac 桌面檔案 – 讓你凌亂的桌面不會被看見 - TechMoon 科技月球...
原文網址:[快速] 一行指令暫時隱藏 Mac 桌面檔案 – 讓你凌亂的桌面不會被看見 首發於:科技月球 TechMoon 有時當我們要拍攝桌面照片時,或是遇到要展示電腦時,需要使用到桌面. 此時如果不 ...
- CCD 輸出雜訊(Readout Noise)及輸出速度(Readout Speed)
http://zip.nvp.com.tw/forum.php?mod=viewthread&tid=1206&extra=page%3D3 輸出雜訊(Readout Noise) : ...
- 安裝SQL2012 出現規則Microsoft .NET應用程式安全性產生警告
安裝SQL2012 出現規則"Microsoft .NET應用程式安全性"產生警告 解决方法 http://crl.microsoft.com/pki/crl/products/M ...
- SQL2008R2 Reporting Services 報表產生器 3.0 快速上手
今天去客戶那邊教了一堂 SQL Server 2008 R2 Reporting Services 基礎課程,雖然短短三個小時能教的東西不多但重點應該都點到了,而且快速上手之後只要有資料在手,透過內建 ...
- matlab源知识库,MATLAB產生隨機數
(1)用計算機產生的是"偽隨機數".用投色子計數的方法產生真正的隨機數 , 但電腦若也這樣做 , 將會占用大量內存 ; 用噪聲發生器或放射性物質也可產生真正的隨機數 , 但不可重復 ...
- 如何強迫 .Net 應用程式輸出英文的例外訊息
转自:http://feeds.feedburner.com/~r/TheWillWillWeb/~3/358986630/post.aspx 因為常常需要跟國外 Blogger 交流,甚至回報某些國 ...
- java冒泡排序找最大的值_(13)數組操作:遍歷、輸出最大值、冒泡排序、選擇排序,java已有的排序方法、折半查找...
1.數組遍歷 /* * 獲取數組中元素,遍歷 */ int []y=new y[3]; for(int i=0;i { System.out.println("y["+i+&quo ...
- signature=94f3cd0155e1d8c8ff09aa94177adccd,研擬顆粒流與連體數值耦合方法模擬山崩產生之震動訊號...
摘要: 本研究首先以二維顆粒流程式(PFC)模擬小林村崩塌,將垂直力量所記錄之震動訊號利用Hilbert-Huang transform (HHT)加以分析,將四個監測點所得到之震動訊號繪製成時頻圖, ...
- ABAP將數字輸出前面補0
將數字輸出前面補0 Function: CONVERSION_EXIT_ALPHA_INPUT 程式碼 DATA: test(5), value LIKE regup-wrbtr VALU ...
最新文章
- java前后端分离账号错误_前后端分离,获取token,验证登陆是否失效
- Qt Creator添加套件
- [zz]为 Lua 绑定 C/C++ 对象
- linux下ceontab不起作用,linux下crontab 不能执行的原因
- The 6th Zhejiang Provincial Collegiate Programming Contest-ProblemA:Second-price Auction
- 基于Lumisoft.NET组件的POP3邮件接收和删除操作
- mvc core2.1 Identity.EntityFramework Core 导航状态栏(六)
- 解决android sdk 无法更新
- ak和sk怎么认证 海康威视_JWT和HMAC(AK/SK)认证方式使用场景
- SQL:解决PostgreSQL数据库传输出现ERROR: invalid byte sequence for encoding “UTF8“: 0xe5 0x9b 0x20
- java 与 php 区别或异同(整理、整合)
- linux系统支持网银吗,Linux系统能使用网银吗?
- 用国外的服务器有什么样的优势吗?
- Ruby(了解第二天)
- 都挺好 苏大强C位出道的不只表情包 还有大眼袋
- 爬虫:UnicodeDecodeError: 'gbk' codec can't decode byte 0xa6 in position
- 解决导入maven项目之后pom.xml中的project标签报错:批量删除没有下载完全的pom依赖bat脚本
- vscode调试js
- Kubernetes实战吴龙辉
- 【Windows取证】隐藏用户