Tuesday, April 6, 2010

Ruby and jQuery -- $(document).ajaxSend() not modifying the params as expected

Programmer Question

I cannot get jquery's ajaxSend (http://api.jquery.com/ajaxSend/) to properly modify the parameters. I have:



$(document).ajaxSend(function(event, request, settings) {
settings.data = $.deparam(settings.data);
settings.data['random'] = new Date().getTime();
settings.data['_method'] = 'get';
settings.data = $.param(settings.data)
$.log(settings);
});


$(document).ready(function() {
//...snip...
$.ajaxSetup({
data : {
remote : 1,
authenticity_token : encodeURIComponent(AUTH_TOKEN)
}
});
});


The idea here is that we always want 4 param sent across: remote and auth_token always get set properly. However, random and _method (both needed for IE issues) do not get set. Logging settings inside ajaxSend shows me that they are set to settings.data:



"remote=1&authenticity_token=6GA9R_snip_253D&random=1270584905846&_method=get"


but when it gets sent across the wire, I only have the following:



  authenticity_token 6GA9R_snip_253D
remote 1


Why in the world is this not working?



Find the answer here

No comments:

Post a Comment

LinkWithin

Related Posts with Thumbnails