I’m trying to avoid handling this improperly encoded request on the server. I have a request with a single parameter like this:
$.ajax({
url: "http://someplace.ontheinternets/count?",
data: {
days_since_epoch: 15460
},
dataType: "json",
success: function(data) {
// Do something with data
}
});
This is giving me: http://someplace.ontheinternets/count?&days_since_epoch=15460
The leading ampersand is giving me problems on the other end (interpreted as two parameters with the first one being empty). Seems like an easy fix, but I did not see this specific issue in the related questions. Any suggestions would be helpful.
Don’t put the
?on it in yoururlparameter. Since you have it there, jQuery thinks the URL already has other parameters, and so adds the ones you asked it to add using an&. If you remove the?from the end of yoururlparameter, jQuery won’t be fooled and will (for a single parameter) just use?.