If I take the same amount of time writing this article as I did finding the problem, then this article would probably be 50,000 words long. However; I also know that articles are supposed to help individuals quickly solve problems and be enjoyable to read therefore; I had to adjust accordingly. I found this solution after hours on the internet trying to solve a problem that was created when I upgraded the jquery library from 1.6.1 to 1.8.3. I cannot prove (yet) that Jquery ultimately caused this problem but I can say that when I use any development tool at my disposal I see something quite interesting. Let’s play a game of what’s different. Look at following two sets of code and tell me what is different between them. There is a lot of other code but this is what is important.
CODE A
[code language=”javascript”]
$.ajax({
url: "/api/Contact",
data: JSON.stringify(dataString),
type: "POST",
contentType: "application/json;charset=utf-8",
statusCode: {
201: function (newMovie) { success(newMovie); },
400: function (xhr) {
var errors = JSON.parse(xhr.responseText);
fail(errors);
}
}
});
[/code]
CODE B
[code language=”javascript”]
$.ajax({
url: "/api/Contact/",
data: JSON.stringify(dataString),
type: "POST",
contentType: "application/json;charset=utf-8",
statusCode: {
201: function (newMovie) { success(newMovie); },
400: function (xhr) {
var errors = JSON.parse(xhr.responseText);
fail(errors);
}
}
});
[/code]
Did you catch it? It is very easy to miss. If you saw it in line 2 then you win. You see without the ‘/’ at the end no matter what else I tried it sends the request as a GET even if you declare it a POST. You can see from the screen shots below the result of CODE A and CODE B. This problem did not rear its ugly head until I upgraded to Jquery 1.8.
CODE A RESULTS
CODE B RESULTS
This proved to take hours the other day to find but 30 seconds to correct. I hope you enjoyed reading this article while also getting to play a small game. If not then let me know and I can try and send you my first draft of this article. I have yet to actually find the real reason for this but nevertheless this solved my problem. Time to move onto the next problem.
Looking for quality web hosting? Look no further than Arvixe Web Hosting!
Thanks for the article, David. You saved me some serious debugging time.
I shouldve googled this before spending hours debugging. Thanks!
You’re my hero. Thanks!
Thanks David, It saved me 🙂