madrobby/zepto — Issue #319: CORS request fails when sending empty string for data
Author: pamelafox
Created: 2011-11-19 01:01:47+00:00
State: open

If I specify an empty string for data in an AJAX request, the request fails due to CORS error ("not allowed by Access-Control-Allow-Origin."). It works fine with jQuery $.ajax and works fine if I pass in null instead. Perhaps it's a mistake to pass in an empty string, I'm not sure, but it took some debugging to figure out why it wasn't working.

Code:
$.ajax({
url: url,
type: 'POST',
data: '',
dataType: 'json',
xhrFields: {
withCredentials: true
},
success: function(responseJSON, textStatus, xhr) {
},
error: function(xhr, textStatus, errorThrown) {
}
});