1
由於某些原因,當我從jQuery(1.4.4)向CherryPy服務器(3.1.2)發出刪除HTTP請求時,沒有參數正在發送。 POST,GET和PUT請求正在發送參數。從jQuery DELETE請求到CherryPy不發送參數
這裏的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)
和這裏的index.html的使用jQuery代碼:
<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>
這就是BEING從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請求沒有發送正確的參數?