没有通过jquery发布请求
post request with jquery not going through
所以我有下面的jquert代码
$.ajax({
url: '/game',
type: 'post',
dataType: 'json',
success: function (data) {
if (data.status != "ok") {
console.log(data);
alert(data);
}
},
data: {game_id : 1, game_stage : 1}
});
或者即使我把它改成这个
$.post("/game", {game_id:1, game_stage:1}, function(data) {
if (data.status != "ok") {
console.log(data);
alert(data);
}
}, 'json');
我有一个C++服务器来调试它,它只输出发送过来的原始HTTP请求,出于某种原因,我总是得到
POST /game HTTP/1.1
Host: localhost:5000
Accept: application/json, text/javascript, */*; q=0.01
X-Requested-With: XMLHttpRequest
Accept-Language: en-us
Accept-Encoding: gzip, deflate
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
Origin: http://localhost:5000
Content-Length: 22
Connection: keep-alive
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_3) AppleWebKit/601.4.4 (KHTML, like Gecko) Version/9.0.3 Safari/601.4.4
Referer: http://localhost:5000/
DNT: 1
为什么JSON对象没有被传递到请求中?类似的GET请求也可以正常工作。
这是我第一次使用JavaScript,所以请原谅我的愚蠢错误
尝试更改
url: '/game',
至
url: 'game',
我假设"game"在当前目录中,没有扩展名。
试着这样使用:
$.ajax({
url: '/game',
type:"POST",
data: {game_id : 1, game_stage : 1} ,
contentType:"application/json; charset=utf-8",
dataType:"json",
success: function(data){
if (data.status != "ok") {
console.log(data);
alert(data);
}
}
});
相关文章:
- 有关插入适配器的错误。[错误]请求从 'back_insert_iterator<vector<>>' 类型转换为非标量类型
- 如何在boost beast http请求中设置http头
- 发送一个带有libcurl C++问题的帖子请求:s
- 在多个核心中处理一个HTTP请求
- 错误:请求非类类型为"MULTIMEDIA_FILME [500]"的成员|
- 使用 Winsock2.h C++向不和谐 API 发送 HTTP 请求时出现问题
- 每个服务器请求的内存预算
- std::getline没有在while循环中重新请求用户输入
- 请求最简单的 OpenMP 目标 GPU 示例
- 请求有关C++中嵌入 for 循环的帮助
- 错误:请求从"常量字符 [5]"转换为非标量类型"字符串"
- 使用 winsock 接收 http 请求
- QNetworkAccessManager 稍后在添加请求时删除
- 为什么我收到来自谷歌的错误请求?
- 从网链套接字请求连接设备的列表
- libcurl :C++处理多个异步请求
- 对于 http 请求,python 比 c++ 快吗?
- 通过引用传递向量是请求 std::分配器
- 为什么当通过 TCP 发送的消息速率增加时,请求-响应消息对的延迟会降低?
- pThread 中的 curl 请求在请求完成后崩溃