gpt4 book ai didi

jquery - 从 jQuery 到 CherryPy 的 DELETE 请求不发送参数

转载 作者:可可西里 更新时间:2023-11-01 17:03:58 26 4
gpt4 key购买 nike

出于某种原因,当我从 jQuery (1.4.4) 向 CherryPy 服务器 (3.1.2) 发出 DELETE HTTP 请求时,没有发送任何参数。 POST、GET 和 PUT 请求可以正常发送参数。

这是 CherryPy 服务器代码:

import cherrypy

class DeleteExample(object):
exposed = True

def PUT(self, *args, **kwargs):
print kwargs

def DELETE(self, *args, **kwargs):
print kwargs

global_conf = {'global': {'server.socket_port': 8080},
'/': {'request.dispatch': cherrypy.dispatch.MethodDispatcher(),
'tools.staticdir.root': '/home/kevin/workspace/delete_example',
'tools.staticdir.on': True,
'tools.staticdir.dir': 'src',
'tools.staticdir.index': 'index.html'}
}
cherrypy.quickstart(DeleteExample(), config=global_conf)

这是带有 jQ​​uery 代码的 index.html:

<html>
<head>
<script type="text/javascript" src="jquery-1.4.4.js"></script>
<script>
$(document).ready(function() {
$.ajax({
type: "PUT",
url: "http://localhost:8080",
dataType: "json",
data: {first: 10, second: 200}
});

$.ajax({
type: "DELETE",
url: "http://localhost:8080",
dataType: "json",
data: {first: 10, second: 200}
});
});
</script>
</head>
<body>
</body>
</html>

这是从 CherryPy 网络服务器打印出来的内容:

{'second': '200', 'first': '10'}
127.0.0.1 - - [23/Jan/2011:04:02:48] "PUT / HTTP/1.1" 200 19 "http://localhost:8080/" "Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.13) Gecko/20101206 Ubuntu/10.04 (lucid) Firefox/3.6.13"
{}
127.0.0.1 - - [23/Jan/2011:04:02:51] "DELETE / HTTP/1.1" 200 19 "http://localhost:8080/" "Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.13) Gecko/20101206 Ubuntu/10.04 (lucid) Firefox/3.6.13"

如您所见,使用 .ajax 函数发出的 PUT 和 DELETE 请求除了类型外完全相同。但是,出于某种原因,PUT 发送所有参数,而 DELETE 不发送任何参数。

有人知道为什么 DELETE 请求没有发送正确的参数吗?

最佳答案

您似乎正在尝试发送带有请求正文的 DELETE 请求,这...不寻常。 (同样适用于 GET)。

关于jquery - 从 jQuery 到 CherryPy 的 DELETE 请求不发送参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4772135/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com