ajax 中,通过 req 获取 json, 发送方法如下
- var handlerFunction = attrsHandler(req,fAlias);
- req.onreadystatechange = handlerFunction;
- req.open("POST", "url", true);
- // Specify that the body of the request contains form data
- req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
- // Send form encoded data stating that I want to add the
- // specified item to the cart.
- req.send("a=" + 1 + "&b=-1" + "&c=" + c);
得到响应代码后,需要做如下处理才可当做 object
- var jsonExpression = "(" + req.responseText + ")";
- var family = eval(jsonExpression);
本文介绍了如何使用Ajax发送POST请求并接收JSON响应的方法。详细展示了设置请求头、发送表单数据及解析响应的过程。

397

被折叠的 条评论
为什么被折叠?



