1

I have a webapp written in rails and jQuery that's giving me a mysterious AJAX problem in Firefox.

When I make a certain AJAX request against my localhost rails server, jQuery calls the request's error event handler with no interesting error information, printing the arguments to the console reveals only:

[Object { readyState=0, status=0, statusText="error"}, "error", ""]

Interestingly, the server does receive the request and claims it responds successfully; certainly it does the server-side work it was supposed to. Neither HTTPScoop nor Wireshark have been able to give me any love in sniffing traffic on the loopback interface for some reason. Firebug doesn't report any response information, just an angry red X.

Even more interestingly, I get different behavior on heroku. In that case, the AJAX request still fails with no interesting error information given, firebug reports the angry red X, but the server never even receives the request.

It seems to be something with Firefox. Curl is able to POST the request successfully, and Safari and Chrome both run the application fine.

The problem isn't systemic. I have several other model objects that use the same pattern to save themselves to the server, and they work perfectly. Indeed, if the model is a different type: a line drawn freehand instead of segments, it works perfectly.

For what it's worth, the POST data of a failing request might be something like:

wall[kind]  wall
wall[vertex_values][0][x]   -60
wall[vertex_values][0][y]   -3
wall[vertex_values][1][x]   -55
wall[vertex_values][1][y]   2
wall[vertex_values][2][x]   -55
wall[vertex_values][2][y]   -1
wall[vertex_values][3][x]   -55
wall[vertex_values][3][y]   -4

wall%5Bkind%5D=wall&wall%5Bvertex_values%5D%5B0%5D%5Bx%5D=-60&wall%5Bvertex_values%5D%5B0%5D%5By%5D=-3&wall%5Bvertex_values%5D%5B1%5D%5Bx%5D=-55&wall%5Bvertex_values%5D%5B1%5D%5By%5D=2&wall%5Bvertex_values%5D%5B2%5D%5Bx%5D=-55&wall%5Bvertex_values%5D%5B2%5D%5By%5D=-1&wall%5Bvertex_values%5D%5B3%5D%5Bx%5D=-55&wall%5Bvertex_values%5D%5B3%5D%5By%5D=-4

While a successful request looks like:

wall[kind]  drawing
wall[vertex_values][0][x]   -50.0469798657718
wall[vertex_values][0][y]   1.0961968680089402
wall[vertex_values][1][x]   -49.77852348993288
wall[vertex_values][1][y]   0.9172259507829903
wall[vertex_values][2][x]   -49.51006711409395
wall[vertex_values][2][y]   0.7382550335570386
wall[vertex_values][3][x]   -49.331096196868
wall[vertex_values][3][y]   0.6487695749440636
wall[vertex_values][4][x]   -49.107382550335565
wall[vertex_values][4][y]   0.604026845637577
wall[vertex_values][5][x]   -48.92841163310961
wall[vertex_values][5][y]   0.5592841163310887
wall[vertex_values][6][x]   -48.838926174496635
wall[vertex_values][6][y]   0.5592841163310887
wall[vertex_values][7][x]   -48.749440715883665
wall[vertex_values][7][y]   0.5592841163310887

wall%5Bkind%5D=drawing&wall%5Bvertex_values%5D%5B0%5D%5Bx%5D=-50.0469798657718&wall%5Bvertex_values%5D%5B0%5D%5By%5D=1.0961968680089402&wall%5Bvertex_values%5D%5B1%5D%5Bx%5D=-49.77852348993288&wall%5Bvertex_values%5D%5B1%5D%5By%5D=0.9172259507829903&wall%5Bvertex_values%5D%5B2%5D%5Bx%5D=-49.51006711409395&wall%5Bvertex_values%5D%5B2%5D%5By%5D=0.7382550335570386&wall%5Bvertex_values%5D%5B3%5D%5Bx%5D=-49.331096196868&wall%5Bvertex_values%5D%5B3%5D%5By%5D=0.6487695749440636&wall%5Bvertex_values%5D%5B4%5D%5Bx%5D=-49.107382550335565&wall%5Bvertex_values%5D%5B4%5D%5By%5D=0.604026845637577&wall%5Bvertex_values%5D%5B5%5D%5Bx%5D=-48.92841163310961&wall%5Bvertex_values%5D%5B5%5D%5By%5D=0.5592841163310887&wall%5Bvertex_values%5D%5B6%5D%5Bx%5D=-48.838926174496635&wall%5Bvertex_values%5D%5B6%5D%5By%5D=0.5592841163310887&wall%5Bvertex_values%5D%5B7%5D%5Bx%5D=-48.749440715883665&wall%5Bvertex_values%5D%5B7%5D%5By%5D=0.5592841163310887

I'm completely perplexed. Have I hit the weirdest bug ever in Firefox, or am I doing something so stupid it's unfathomable to me?

Donald ball
  • 273
  • 1
  • 11
  • As is so often the case when it comes to these things, the act of describing it fully leads to the solution. The culprit was the key used to trigger the AJAX request. In this case, it was the ESC key. In Firefox, by default, hitting ESC cancels the HTTP request. The fact that it works against AJAX requests is interesting and new to me, as is the fact that it works against localhost but not against a remote server. In any case, a simple evt.preventDefault() gives the correct behavior and restores my sanity. – Donald ball Apr 05 '11 at 04:26
  • possible duplicate of [How to return the response from an AJAX call?](http://stackoverflow.com/questions/14220321/how-to-return-the-response-from-an-ajax-call) – Paul Sweatte Mar 25 '14 at 15:52

0 Answers0