2
votes

I have a jQuery ajax call that is working fine in IE, but continually errors in Chrome and Firefox. I have similar ajax calls elsewhere in my application and they work fine in all browsers but for some reason this one doesn't.

First off, is there something obvious that I am doing here that would break in browsers other than IE, and second and just as important, is there a way to get something meaningful out of the error: function (e) {} block?

                $.ajax({
                type: "POST",
                url: "http://localhost:52350/FabRouting/Webservice/FinalizeFileStream.asmx/FinalizeFileStreamDoc",
                data: JSON.stringify({ DocID: docID, FileSize: file.size }),
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (data) {
                    if (data.d.length == 0) {
                        //error
                        $("[id$=txtResult]").val("error 0");
                    }
                    else {
                        $("[id$=txtResult]").val(data.d[0].Result);
                    }
                },
                error: function (e) {
                    //error
                    $("[id$=txtResult]").val("error");
                }
            });
2
Open console (F12) and check what the error says. It should return an asp.net error page (if you don't have customer errors on)bobek
JSON.stringify is avalaible in some but not all browsers. You would need to add a library (such as json2.js ) to add that function to browsers that don't support it.Nick Bork
Did you alert(e) or console.log(e) to see what is? Also, try using Chrome dev tools. (Hit Ctrl+Shift+J), open up the console to view the error. Tell me what it says.The Internet
The console shows that it is in fact being called and the Post does have my data in it in what appears to be the correct format. The Response is blank though.divtag
I am using the JSON.stringify in other places and it is working fine in the browsers I am targeting. The Post does seem to be posting what I have so it appears to be working here too.divtag

2 Answers

3
votes

The error function has three parameters

error: function(jqXHR, textStatus, errorThrown) { //code here }

while you're only using one. errorThrown should have some more useful information.

EDIT2 - Scratch my answer about it breaking because of the keys not being strings - that should be fine. However, why are you stringifying the data if you are using a post? You should be able to pass the json array directly.

0
votes

It ended up not being my code or the browsers (well kinda) after all, just my error.

I kept researching and read something where someone was having trouble with a cross-domain ajax call giving errors. I am not trying to do that, however I did have two Visual Studio web servers spun up for some reason. I looked and I was calling the webservice with a hard coded url (http://localhost:52350/FabRouting/Webservice.......)for the time being and I was using the new url (http://localhost:59986/FabRouting/Tes.....) to access the page.

This was working fine in IE for some reason, but when I was trying it in Chrome or Firefox it was not working. I changed where I was accessing the page and I got a good return value from the ajax call.

I would still like to know how to get a more meaningful error and @dtryan has me part way there. If anyone can help me figure that out I will mark theirs as the answer and not this answer.

EDIT: I later found that I was in fact able to get error messages the way I was trying before and the way @dtryan was suggesting as well. The problem was that for some reason since this was throwing an error because it was trying to go cross-domain, but I wasn't able to capture that error.

I have since had out of memory errors, etc and those I am able to capture and see just fine. I think this just was a perfect storm causing the errors not to be visible. If anyone has any way to capture these errors it would be good to know.