2011-01-23 36 views
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请求没有发送正确的参数?

回答

3

看来你试图发送DELETE请求与请求正文,这是... 不寻常的。 (同样适用于GET)。