I'm working on a script that posts simple commands to a web server embedded on a device. I'm not sure exactly what the server is (some flavor of Apache on embedded Linux, I believe) and it shouldn't matter for what I'm asking.
The code on the server is reacting differently to a URL sent from jQuery's $.ajax()
function and the exact same URL sent from Chrome. I'm trying to find a way to figure out what Chrome is doing with this request that jQuery is not in order to make my javascript work.
Details:
When I post to the device to send it a command, I do it like this:
$.ajax({
type: "GET",
url: urlPrefix+'/setsetting/'+name+'='+value,
success: function(r) {
//command was sent
},
error: function(e) {
//some http error
}
});
When I make a request in which the value does not contain spaces, the server does its job properly. However, when I make a request where the value does contain spaces, the server doesn't do it's job. So there is obviously a problem with how the code on the server is handling spaces in the URL, right? Here's the weird thing: When I take a URL constructed with this code and put it directly into my browser window, the server does its job even if there is a space in the value. So this URL sent from my script:
http://[ip]/setsetting/setting1=value 1
does not work, but if I plug that same url into my browser (Chrome), it does work. Chrome will change the space to %20
. I've tried formatting the value in my code to replace spaces with %20
which doesn't help. I've tried adding the contentType attribute of $.ajax()
to other things and none of that helped.
Edit: I just noticed that the error function of $.ajax() is firing. e.responseText is an html page that says "400 - Bad Request". Hmmm?