I use jQuery (1.4.2) with the Django backend and am developing with Firefox (3.5.15) on Debian. I use $ .ajax () to send some data to my server, which reflects the data back to the browser. Firefox sends a POST, and then immediately performs a GET at the same URL. Where is GET from? I do not want this to happen.
The code I use for POST is as follows:
$.ajax({
type: 'POST',
url: '/edit_value/',
data: JSON.stringify(data_to_post),
success: function(updated) {
alert('success');
},
error: function(request, description, exception) {
alert('error');
},
async: false,
dataType: 'json'
});
I see a warning message, not an error message. Looking at my server logs, I correctly return data_to_post.
I looked at tcpdump and looked at the POST request. It looks as I expected:
POST /edit_value/ HTTP/1.1
Host: localhost:8000
User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.15) Gecko/20101028 Iceweasel/3.5.15 (like Firefox/3.5.15)
Accept: application/json, text/javascript, */*
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
X-Requested-With: XMLHttpRequest
Referer: http://localhost:8000/
Content-Length: 30
Cookie: csrftoken=9e3edd79a51956f088f4a505ca1b4282; sessionid=80d72430f4682632ccfb8dc8047b7d17
Pragma: no-cache
Cache-Control: no-cache
[{"id":"161","value":"988.0"}]
The answer also looks fine:
HTTP/1.0 200 OK
Date: Mon, 22 Nov 2010 07:28:44 GMT
Server: WSGIServer/0.1 Python/2.6.6
Vary: Cookie
Content-Type: text/json
[{"id":"161","value":"988.0"}]
async true, TCP-, /. async false, / ( false). Firefox GET.
GET /edit_value/ HTTP/1.1
Host: localhost:8000
User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.15) Gecko/20101028 Iceweasel/3.5.15 (like Firefox/3.5.15)
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
Referer: http://localhost:8000/
Cookie: csrftoken=9e3edd79a51956f088f4a505ca1b4282; sessionid=80d72430f4682632ccfb8dc8047b7d17
GET? Firebug ? ?
,
Craig