I'm trying to pass a simple stringified int array into a json exression and sent through ajax. The request url and headers all look fine to me going from client to server, but in Cake the request->query vardumps empty for some reason.
Headers from ajax:
Request URL:http://localhost/cakephp-2.2.5/paragraphs/sortPublished.json?[%221%22,%223%22,%222%22]
Request Method:GET
Status Code:200 OK
Request Headersview source
Accept:application/json, text/javascript, */*; q=0.01
Accept-Charset:ISO-8859-1,utf-8;q=0.7,*;q=0.3
Accept-Encoding:gzip,deflate,sdch
Accept-Language:fi-FI,fi;q=0.8,en-US;q=0.6,en;q=0.4
Connection:keep-alive
Content-Type:application/json; charset=utf-8
Cookie:CAKEPHP=gu46lhu6lohe1hnr4vmeve23g1
DNT:1
Host:localhost
Referer:http://localhost/cakephp-2.2.5/paragraphs/edit/1
User-Agent:Mozilla/5.0 (Windows NT 6.0) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.64 Safari/537.31
X-Requested-With:XMLHttpRequest
Query String Parametersview sourceview URL encoded
["1","3","2"]:
Response Headersview source
Connection:Keep-Alive
Content-Length:425
Content-Type:application/json; charset=UTF-8
Date:Mon, 13 May 2013 09:11:14 GMT
Keep-Alive:timeout=5, max=98
Server:Apache/2.4.3 (Win32) OpenSSL/1.0.1c PHP/5.4.7
X-Powered-By:PHP/5.4.7
And the Javascript
$(document).ready(function(){
$("#button").click(function() {
var sortedParagraphs = $( "#sortable1" ).sortable('toArray');
var key_value_pairs = [];
var i = 0;
$.each( sortedParagraphs, function(index, value) {
key_value_pairs[index] = value;
});
$.ajax({
url: define1,
data: JSON.stringify(sortedParagraphs),
dataType: "json",
contentType: 'application/json; charset=utf-8',
success: function(data) {
alert(data);
}
});
});
});
For my amateur self it would appear clear that the JSON is formed correctly and I can't see any problems with the url, but request->query still produces:
array(0) {
}
I've been wrestling with this tiny problem since forever it feels, and any help would be appreciated.