记录JS XMLHttpRequest POST提交JSON数据的格式
json
适用于现代 C++ 的 JSON。
项目地址:https://gitcode.com/gh_mirrors/js/json
免费下载资源
·
刚开始时进入误区,在服务器端无法读取到正常的Json对象
function postJson() {
// var obj = {};
// obj.name = "testNmae";
// obj.text = "测试内容";
// var temp = JSON.parse(obj);
var temp = "name=" + "testName" + "&" + "text=" + "测试内容";
var httpRequest = new XMLHttpRequest();//第一步:创建需要的对象
httpRequest.open('POST', url, true); //第二步:打开连接/***发送json格式文件必须设置请求头 ;如下 - */
httpRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
//设置请求头 注:post方式必须设置请求头(在建立连接后设置请求头)var obj = { name: 'zhansgan', age: 18 };
httpRequest.setRequestHeader("Access-Control-Allow-Origin", "*");
httpRequest.send(temp);//发送请求 将json写入send中
/**
* 获取数据后的处理程序
*/
httpRequest.onreadystatechange = function () {//请求后的回调接口,可将请求成功后要执行的程序写在其中
if (httpRequest.readyState == 4 && httpRequest.status == 200) {//验证请求是否发送成功
var jsonStr = httpRequest.responseText;//获取到服务端返回的数据
var json = JSON.parse(jsonStr);
console.log(json);
}
};
}
后来直接找到Web文档才找到解决方法。
GitHub 加速计划 / js / json
18
5
下载
适用于现代 C++ 的 JSON。
最近提交(Master分支:3 个月前 )
2134cb94
* change NLOHMANN_JSON_FROM_WITH_DEFAULT to let NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT work with an empty JSON instance
* fix ci_static_analysis_clang (ci_clang_tidy)
* change NLOHMANN_JSON_FROM_WITH_DEFAULT to let NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT work with an empty JSON instance 2 天前
6057b31d
* :wrench: overwork astyle call
* :wrench: overwork astyle call
* :wrench: overwork astyle call
* :wrench: overwork astyle call
* :wrench: overwork astyle call
* :wrench: overwork astyle call
* :wrench: overwork astyle call
* :wrench: overwork astyle call
* :wrench: overwork astyle call
* :wrench: overwork astyle call
* :wrench: overwork astyle call
* Use ubuntu-latest image to run Valgrind (#4575)
* :wrench: use Clang image to run valgrind
* :wrench: use Clang image to run valgrind
* :wrench: use Clang image to run valgrind
* :wrench: use Ubuntu image to run valgrind
* Use Clang image to run iwyu (#4574)
* :wrench: use Clang image to run iwyu
* :wrench: use Clang image to run iwyu
* :wrench: overwork astyle call
* :wrench: overwork astyle call
* :wrench: overwork astyle call
* :wrench: overwork astyle call
* :wrench: overwork astyle call
* :wrench: overwork astyle call
* :wrench: overwork astyle call
* :wrench: overwork astyle call
* :wrench: overwork astyle call
* :wrench: overwork astyle call
* :wrench: overwork astyle call
* :art: format code
* :hammer: clean up 3 天前
更多推荐
已为社区贡献3条内容
所有评论(0)