ajax POST request being sent as GET

68 views
Skip to first unread message

Larry Martell

unread,
Dec 15, 2015, 5:25:12 PM12/15/15
to django...@googlegroups.com
I am sending an ajax POST request like this:

$.ajax({
url: url,
method: 'POST',
dataType: "json",
data: {
recipe: recpie
}
})

But the request is being sent as a GET:

Request URL: http://127.0.0.1/api/update_measbox?recipe=MALBHDPOR
Request Method: GET
Status Code:200 OK
Remote Address:127.0.0.1:80

Any ideas as to why this is happening and how I can get it sent it as a POST?

Daniel Chimeno

unread,
Dec 15, 2015, 5:45:31 PM12/15/15
to Django users
Hello,

This is more  a jQuery issue than a Django one, but it could be because of the quotes.


var menuId = $( "ul.nav" ).first().attr( "id" );
var request = $.ajax({
 url: "script.php",
 method: "POST",
 data: { id : menuId },
 dataType: "html"
});


Larry Martell

unread,
Dec 15, 2015, 6:59:10 PM12/15/15
to django...@googlegroups.com
On Tue, Dec 15, 2015 at 5:45 PM, Daniel Chimeno <dan...@chimeno.me> wrote:
> Hello,
>
> This is more a jQuery issue than a Django one, but it could be because of
> the quotes.
>
> From: http://api.jquery.com/jquery.ajax/
>
> var menuId = $( "ul.nav" ).first().attr( "id" );
> var request = $.ajax({
> url: "script.php",
> method: "POST",
> data: { id : menuId },
> dataType: "html"
> });

No, the double quotes vs. single quotes do not matter. I think this is
somehow related to my django app, as when I send the same request from
a web page not part of my django app it does get sent as a POST.


>
> El martes, 15 de diciembre de 2015, 23:25:12 (UTC+1), Larry....@gmail.com
> escribió:
>>
>> I am sending an ajax POST request like this:
>>
>> $.ajax({
>> url: url,
>> method: 'POST',
>> dataType: "json",
>> data: {
>> recipe: recpie
>> }
>> })
>>
>> But the request is being sent as a GET:
>>
>> Request URL: http://127.0.0.1/api/update_measbox?recipe=MALBHDPOR
>> Request Method: GET
>> Status Code:200 OK
>> Remote Address:127.0.0.1:80
>>
>> Any ideas as to why this is happening and how I can get it sent it as a
>> POST?
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users...@googlegroups.com.
> To post to this group, send email to django...@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/004cad67-925f-41f9-b155-2b3c40d74673%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Neto

unread,
Dec 15, 2015, 10:56:58 PM12/15/15
to Django users
$.post( "ajax/test.html", function( data ) {
 $
( ".result" ).html( data );
});

Simon Charette

unread,
Dec 15, 2015, 11:05:41 PM12/15/15
to Django users
Hi Larry,

It's more of a JavaScript question but my first guess would be
you'd need to use the `type` option instead of `method` because
you are using an old version of jQuery?

Simon

Larry Martell

unread,
Dec 16, 2015, 4:31:58 PM12/16/15
to django...@googlegroups.com
On Tue, Dec 15, 2015 at 11:05 PM, Simon Charette <chare...@gmail.com> wrote:
> Hi Larry,
>
> It's more of a JavaScript question but my first guess would be
> you'd need to use the `type` option instead of `method` because
> you are using an old version of jQuery?

That was it. Thank you so much!!
Reply all
Reply to author
Forward
0 new messages