jQuery: The Write Less, Do More JavaScript Library

DELETE HTTP method

View: New views
6 Messages — Rating Filter:   Alert me  

DELETE HTTP method

by Yosifov Pavel-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Can somebody show example how to send via AJAX DELETE HTTP method
instead of POST, like this:
   $.post( '/filial/del/', {city:$.trim(city)} );

but DELETE.

I tried:
  $.ajax( {url:'/filial/del/', type:'DELETE',
data:'city='+encodeURI($.trim(city))} );

and:
  $.ajax( {url:'/filial/del/', dataType:'json', type:'DELETE', data:
{'city':$.trim(city)}} );

but in django vie see that no any 'city' in POST or GET! Is this
possible? I don't see any DELETE in jQuery source...

Re: DELETE HTTP method

by Richard D. Worth-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

From

http://docs.jquery.com/Ajax/jQuery.ajax#options
"
The type of request to make ("POST" or "GET"), default is "GET". Note: Other HTTP request methods, such as PUT and DELETE, can also be used here, but they are not supported by all browsers.
"

- Richard

On Thu, Jul 3, 2008 at 11:23 AM, Yosifov Pavel <bulg@...> wrote:

Can somebody show example how to send via AJAX DELETE HTTP method
instead of POST, like this:
  $.post( '/filial/del/', {city:$.trim(city)} );

but DELETE.

I tried:
 $.ajax( {url:'/filial/del/', type:'DELETE',
data:'city='+encodeURI($.trim(city))} );

and:
 $.ajax( {url:'/filial/del/', dataType:'json', type:'DELETE', data:
{'city':$.trim(city)}} );

but in django vie see that no any 'city' in POST or GET! Is this
possible? I don't see any DELETE in jQuery source...


Re: DELETE HTTP method

by Yosifov Pavel-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


So, real REST is impossible, because of browser limitations? And to
make correct cruD in REST I must use GET/POST only, right?
And another question: but WHY jQuery doesn't process 'DELETE' method
as 'GET': it doesn't parse data to result url. It do it only for POST
and GET. OK, not all browsers support it, but why jQuery doesn't
support other HTTP methods in principle?

/Pavel Yosifov

Re: DELETE HTTP method

by Yosifov Pavel-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Hmm, after googling I saw that problems not in XMLHttpRequest - it can
do DELETE in all browsers. Richard, you mean HTML forms only? But I
mean DELETE via ajax in jQuery without any forms...

Re: DELETE HTTP method

by Chris Bailey-4 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I think you said you were using Django?  I suggest looking at what technique it uses to do REST/DELETE and such.  Rails uses the trick where it does DELETE and such as a POST with a "_method=delete" argument.  I would imagine Django has a solutio of their own/similar.

On Thu, Jul 3, 2008 at 8:20 PM, Yosifov Pavel <bulg@...> wrote:

Hmm, after googling I saw that problems not in XMLHttpRequest - it can
do DELETE in all browsers. Richard, you mean HTML forms only? But I
mean DELETE via ajax in jQuery without any forms...



--
Chris Bailey
chris.bailey@...

Re: DELETE HTTP method

by Yosifov Pavel-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


In Django I can't found different between other HTTP methods. It's
only HTTP request to server with method=='DELETE' and Request
dictionary. So, yes, Django "manage", "understand" HTTP DELETE so
good, so other HTTP methods. And params are in request. But I need in
this case add params to URL string in jQuery ajax method by hand. And
this work good, but questions about: why jQuery doesn't do it for
DELETE HTTP method like for GET? Why I must do it "by hand" ?!

Best regards,
Yosifov Pavel
LightInTheBox - Buy quality products at wholesale price