Bug Tracker

Opened 12 years ago

Closed 12 years ago

Last modified 12 years ago

#10160 closed bug (worksforme)

AJAX errors are not reported in Firefox Error console

Reported by: macrae_dj Owned by: macrae_dj
Priority: low Milestone: None
Component: ajax Version: 1.6.2
Keywords: Cc:
Blocked by: Blocking:

Description

If a javascript run-time error is present in the success handler of an $.ajax call it is not reported in the Firefox error console (or the Firebug console). This makes debugging very difficult.

Platform: Windows 7 64-bit, Firefox 5.0.1, jQuery 1.6.2. I have also tested in firefox safe-mode.

The contents of 2 files are below. The file that initiates the ajax and the file that responds to the ajax request.

If you uncomment the first 'alert' statement - you will get an error reported as expected. However if you uncomment the second 'alert' statement (inside the 'success' handler) the javascript will crash but there will be no error message in the error console.

ajax_test2.html

<html>
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.6.2.js"></script>
<script type="text/javascript">

$(document).ready(function(){

    //alert(missingVariable1);           //uncomment -> get error reported

    $.ajax({
        url: "ajax_test2_process.php",
        data: "send=hello",
        async: false,
        success: function(data){
            $("#results").append(data);
            //alert(missingVariable2);   //uncomment -> no error reported
            $("#results").append(" finished ");
            }
        });
});

</script>
</head>
<body>
<div id="results"></div>
</body>
</html>

ajax_test2_process.php

<?php
    echo "received: " . $_REQUEST['send'];
?>

Change History (17)

comment:1 Changed 12 years ago by Timmy Willison

Component: unfiledajax
Owner: set to macrae_dj
Priority: undecidedlow
Status: newpending

Thanks for taking the time to contribute to the jQuery project! Please provide a complete reduced test case on jsFiddle to help us assess your ticket.

Additionally, be sure to test against the jQuery Edge version to ensure the issue still exists. To get you started, use this boilerplate: http://jsfiddle.net/FrKyN/ Open the link and click to "Fork" (in the top menu) to get started.

I am unable to reproduce this issue. http://jsfiddle.net/timmywil/bHGGW/

comment:2 Changed 12 years ago by Rick Waldron

A note of advice: Unless you really understand the behaviour produced by setting async: false I would recommend sticking with the default, which is async: true (this is implicit).

comment:3 Changed 12 years ago by macrae_dj

Status: pendingnew

Timmywil, I think maybe my bug report was not very clear. The issue is that errors are not getting reported in the console. Please can you recheck this. I have tried this on 3 machines and have asked others to confirm what I am receiving...

http://stackoverflow.com/questions/7243098/errors-in-jquery-ajax-are-not-getting-reported

It seems clear that this issue does exist.

I understand the attraction of jsfiddle but, in this case, I think its best to use the direct code (as the bug may be due to an interaction with the browser). I.e its best to keep the javascript and the environment the same so the bug can be reproduced reliably (eg lack of an error console on jsfiddle and not being sure if firebug-lite will behave just like firebug etc).

I dont know if this is a bug or its there by necessity - in which case the bug is really a request for a warning in the documentation as I've spent a lot of time trying to resolve this.

There is a link to the web page here...

http://www.alisonstrachan.co.uk/tests/ajax2/ajax_test2.html

Run this and if you dont receive an error in the error console - then you have reproduced the issue.

I have tried to use the Edge version of jQuery but I cant find the link for it (sorry dont know how to use git).

comment:4 Changed 12 years ago by Timmy Willison

Status: newpending

@macrae_dj: I see no reason why you should not be able to reproduce the issue on jsfiddle unless php is required (in that case, it is usually an issue with the server side code and not jQuery). jsfiddle is a normalized environment where we can make proper assumptions. If the issue cannot be reproduced there, it is probably not an issue with jQuery. A test page on your own server does not really help because we need something editable and we need to rule out user error.

PS- you can link tothe git version of jquery here: http://code.jquery.com/jquery-git.js

PSS - jsfiddle is like any other webpage in that it will log to the existing browser console if it exists. Firebug lite is not required and something to keep in mind is that regular firebug will override it and take over logging whether lite is present or not. To see the test page created on jsfiddle by itself, you can add /show to the end of url.

Last edited 12 years ago by Timmy Willison (previous) (diff)

comment:5 Changed 12 years ago by macrae_dj

Status: pendingnew

Timmywil, lets first just see if you can reproduce the bug.

Please click on this link and if you DONT receive an error in the error console - then you have successfully reproduced the issue .... http://www.alisonstrachan.co.uk/tests/ajax2/ajax_test2.html

I have tried your link: http://jsfiddle.net/timmywil/bHGGW/ and I can report I do not receive an error in the Firefox error console (i.e. the bug exists). From your first post I understand that you did receive an error message (as you said you were unable to reproduce the issue). Can you please confirm this.

(When you stated that you couldnt reproduce the issue - I suspected jsfiddle may have been interfering with things and therefore suggested by-passing it).

Last edited 12 years ago by macrae_dj (previous) (diff)

comment:6 Changed 12 years ago by Rick Waldron

Resolution: worksforme
Status: newclosed
Last edited 12 years ago by Rick Waldron (previous) (diff)

comment:7 Changed 12 years ago by macrae_dj

Thanks rwaldron. Could you please also quickly test the direct link http://www.alisonstrachan.co.uk/tests/ajax2/ajax_test2.html

This may help to narrow things down. Its just that I had other folk test with this link and they reported that no error message was received. If you do get an error message, can you let me know the details of you firefox version etc just in case this is has some bearing on the issue.

comment:8 Changed 12 years ago by Rick Waldron

@macrae_dj Please update to: http://code.jquery.com/jquery-1.6.3rc1.js and remove the "async: false" option, ping me here and I wil retest

Version 0, edited 12 years ago by Rick Waldron (next)

comment:11 Changed 12 years ago by macrae_dj

@rwaldron Thanks for testing this out. Appreciated. Do you get the same result for both links (ajax_test2.html and ajax_test2b.html)?

comment:12 Changed 12 years ago by Rick Waldron

No, I did not. In the first file, the result I saw was that no error was reported (as your original filing states) - but that link is irrelevant because it uses an outdated version of the lib and an intentionally broken behaviour (async:false allows users to break the "asynchronous" design of XMLHttpRequest)

Last edited 12 years ago by Rick Waldron (previous) (diff)

comment:13 Changed 12 years ago by macrae_dj

@rwaldron Good. However, I get no error message with either ajax_test or ajax_testb.

I have experimented with Timmy's jsfiddle link and ...

with async I get no error message,

http://www.alisonstrachan.co.uk/tests/ajax2/ajax2_async_true.jpg

with sync I do get the error message.

http://www.alisonstrachan.co.uk/tests/ajax2/ajax2_async_false.jpg

I.e. for me, the bug seems to be present with async operation (can you try this also and see what you get).

It seems like the bug is intermittent/depends on other platform factors etc. Tricky.

I'm a bit worried about what you say about the 'sync' behaviour. In my application, I need one ajax request to complete before the next one starts (its not a publicly available web page, but a script I run locally). I can adjust my own JavaScript to accomplish this and use the async ajax. But that's not the issue, if a feature is available you should be able to use it or at the very least there should be some warnings about it!

Last edited 12 years ago by macrae_dj (previous) (diff)

comment:14 Changed 12 years ago by Rick Waldron

In my application, I need one ajax request to complete before the next one starts

Using async:false is the wrong approach, you should use the $.Deferred object returned by the first ajax call to schedule the next call in the queue. Resources:

The best resource is this presentation: http://vimeo.com/22687950

if a feature is available you should be able to use it or at the very least there should be some warnings about it!

You're right! Which is why it's documented here: http://api.jquery.com/jquery.ajax

async, Boolean Default: true By default, all requests are sent asynchronously (i.e. this is set to true by default). If you need synchronous requests, set this option to false. Cross-domain requests and dataType: "jsonp" requests do not support synchronous operation. Note that synchronous requests may temporarily lock the browser, disabling any actions while the request is active.

comment:15 in reply to:  14 Changed 12 years ago by macrae_dj

You're right! Which is why it's documented here: http://api.jquery.com/jquery.ajax

async, Boolean Default: true By default, all requests are sent asynchronously (i.e. this is set to true by default). If you need synchronous requests, set this option to false. Cross-domain requests and dataType: "jsonp" requests do not support synchronous operation. Note that synchronous requests may temporarily lock the browser, disabling any actions while the request is active.

I read this and was OK with this. This is not a problem for me. This is not the problem we are experiencing here.

Anyway back to the bug. I've tried it on Internet Explorer, and I get an error reported for both async and sync but the message pop-up is different for each. Does this help explain my Firefox is missing some errors...

http://www.alisonstrachan.co.uk/tests/ajax2/ajax2_async_true_ie.jpg

http://www.alisonstrachan.co.uk/tests/ajax2/ajax2_async_false_ie.jpg

Last edited 12 years ago by macrae_dj (previous) (diff)

comment:16 Changed 12 years ago by Rick Waldron

No, it doesn't explain anything as there is nothing more to explain. Please redirect further questions to https://forum.jquery.com/using-jquery

comment:17 Changed 12 years ago by macrae_dj

I give up

Note: See TracTickets for help on using tickets.