Chrome Bug – sends ‘undefined’ when no data is passed to XMLHttpRequest

11 Apr 2010 – Denver, CO

Spent the week trying to juggle work, our 2 year old twins, my parents visiting from Ireland, and repeatedly driving to and from the hospital to spend time with our premature twins that were born on Easter Sunday. Its been a mad, but fun week. I have a secret weapon which has kept me going:


Dunkin Turbo

Turbo! Babies will be home soon and parents are leaving in couple weeks, so life we be returning back to normal. In the meantime, here’s a Google AJAX Chrome bug I experienced this weekend.

Chrome XMLHttpRequest Issue

Its perfectly valid to perform an HTTP POST and send no data, such as the following line of jQuery code:

 
	$.ajax({
	  type: 'POST',
	  url: url,     
	  dataType: 'json'
	});

This should result in no data being sent in the POST but instead, Chrome sends an ‘undefined’ which is incorrect. This is easily fixed by forcing the client-side Javascript to send something:

 
	$.ajax({
	  type: 'POST',
	  data: "",  
	  url: url,     
	  dataType: 'json'
	});

You can find bug reports on the issue here and here.