Question

Pour une raison quelconque quand je fais une requête HTTP SUPPRIMER de jQuery (1.4.4) à un serveur CherryPy (3.1.2), aucun paramètre sont envoyés. POST, GET et demandes de PUT envoient des paramètres très bien.

Voici le code du serveur de 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)

et est ici index.html avec le code 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>

est ce qui est imprimé à partir du serveur Web 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"

Comme vous pouvez le voir PUT et les demandes SUPPRIMER faites avec l'utilisation de la fonction .ajax sont exactement les mêmes, sauf pour le type. Mais, pour une raison PUT envoie tous les paramètres en SUPPRIMER envoie aucun paramètre.

Est-ce que quelqu'un a une idée pourquoi la demande SUPPRIMER n'envoie pas les paramètres appropriés?

Était-ce utile?

La solution

Il semble que vous essayez d'envoyer une demande SUPPRIMER avec un corps de demande, ce qui est ... unusual . (En serait de même GET).

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top