我正在尝试使用XMLHttpRequest对象从表单发送JSON数据.我可以使用以下函数发送数据.FireBug中没有显示错误,请求中的JSON数据显示为FireBug.
但是,我将数据发送到echo.php,简单地返回内容:
<?php
print_r($_POST);
print_r($_GET);
foreach (getallheaders() as $name => $value) {
echo "$name: $value\n";
}
echo file_get_contents('php://input');
?>
Run Code Online (Sandbox Code Playgroud)
POST数组总是为空,但我可以看到返回的JSON字符串file_get_contents.这是怎么发生的?我究竟做错了什么?
echo.php的输出
Array
(
)
Array
(
)
Host: localhost
User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:10.0.2) Gecko/20100101 Firefox/10.0.2
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: eo,de-de;q=0.8,de;q=0.6,en-us;q=0.4,en;q=0.2
Accept-Encoding: gzip, deflate
Connection: keep-alive
Content-Type: application/json; charset=utf-8
Referer: http://localhost/form.html
Content-Length: 88
Cookie: {{..to much data..}}
Pragma: no-cache
Cache-Control: no-cache
{"type":"my_type","comment":"commented"}
Run Code Online (Sandbox Code Playgroud)
发送功能:
function submit(){
var data={};
data.type=document.form.type.value;
data.comment=document.form.comment.value;
//get right XMLHttpRequest object for current …Run Code Online (Sandbox Code Playgroud) 这是我想要学习和做的事情.我有一个JSON文件,其中包含我的产品和详细信息(大小,颜色,描述).在网站上我不能使用PHP和MySQL,我只能使用Javascript和HTML.现在我想要发生的是使用JQuery我可以读取和写入一个JSON文件(JSON文件将作为我的数据库).我不确定是否可以仅使用JQuery和JSON来完成.
首先,如何查询JSON文件?(例如:我会搜索产品的名称和颜色.)
如何解析搜索到HTML的JSON数据?
如何将细节,产品添加到JSON文件?
如果你能指出一个关于我的问题的好教程,那也很棒.
我是JQuery和JSON的新手.
谢谢!