Results 1 to 7 of 7

Thread: Infamous c00c023f error

  1. #1
    Join Date
    Sep 2008

    Infamous c00c023f error


    The following is included in an external js file. The function "doThis()" works perfectly on one page where it is included but throws the 'Could not complete the operation due to error c00c023f' on the line for "if(xmlhttp.readyState==4 && xmlhttp.status==200)" on another page where the same js file is included.

    Search engine results seem to reference the same blog and state that this error is because the ajax call is being aborted before the readyState and status are checked. I'm not aborting it (not intentionally, anyways).

    Any ideas what might be causing this or how to fix it?

    function loadXMLDoc(url,f){
      if (window.XMLHttpRequest){
         if(typeof xmlhttp!='undefined'){
         xmlhttp=new XMLHttpRequest();
         xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    function doThis(){
       process_start();//runs animation
           if (xmlhttp.readyState==4 && xmlhttp.status==200){
              //do something
    I've also tried adding the line "if(xmlhttp.aborted==true){return;}" just before the readyState line but it doesn't fix it.

    Any ideas are appreciated. Thanks!

  2. #2
    Join Date
    Dec 2011
    Centurion, South Africa
    Because the variable xmlhttp is not being declared anywhere, using var, it becomes global and will be shared between each doThis() execution. And because of this, simultaneous requests will just overwrite(abort) the previous one.

    I would suggest either merging the two functions together and properly encapsulating the variables, or have the loadXMLDoc function create a new connection variable and pass it back. This way you can avoid conflict with the request objects.
    Last edited by bionoid; 01-25-2012 at 03:28 AM.
    JavaScript: Learn | Validate | Compact | bionoid

  3. #3
    Join Date
    Sep 2008
    Thank you bionoid for your response.

    Don't I needed xmlhttp to be global so that the loadXMLDoc function will be using the same variable? In this particular example, i'm only running function doThis() once so wouldn't it only be creating and using 1 xmlhttp variable? How would it be aborting?

    By 'encapsulating', are you suggesting to put the two functions into another function together? I use loadXMLDoc in a number of scripts throughout a variety of pages for all of my AJAX calls. so I hope there is another option. Unless you think that it's worth the performance hit to have the loadXMLDoc code in every function that uses these requests?

    A possible solution might be to check if the Ajax call was aborted before checking its readyState and status but I can't seem to find a way to get it to work using the flags.

    What do you think?

  4. #4
    Join Date
    Dec 2011
    Centurion, South Africa

    You have just revealed your problem, the xmlhttp would be shared amongst all the functions calling loadXMLDoc, so there is more than likely a confict on who own the request object at the time.

    This is how I would change your code at the moment:

    function loadXMLDoc(url, f, d)
    	var xmlhttp = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject('Microsoft.XMLHTTP');
    	xmlhttp.onreadystatechange = function() {if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {f(xmlhttp.responseText, xmlhttp);}};
    	xmlhttp.open('POST', url, true);
    	xmlhttp.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
    	xmlhttp.send(d || '');
    	return xmlhttp;
    function doThis()
    	process_start();//runs animation
    	loadXMLDoc('../path/myfile.php', function(response)
    		alert(response); //Received from the server
    	't=' + t);
    You will see that loadXMLDoc now handles the entire request, then calls your callback function at the end.
    Because the xmlhttp is localised it should prevent requests being overwritten.
    Last edited by bionoid; 01-26-2012 at 08:04 AM.
    JavaScript: Learn | Validate | Compact | bionoid

  5. #5
    Join Date
    Sep 2008
    Ah! Brilliant!

    What's the purpose of the second var "xmlhttp" in the onreadystatechange function if the callback only looks for "response"?

    Also i find 'closures' quite confusing and can never seem to keep (what I think are) local variables from being changed by running the function repeatedly. Do I have to worry about that here?

    For example, if I access loadXMLDoc from 2 different functions, how can I be sure the response will "call back" the correct function and reference the correct xmlhttp response?

    Thank you for your help.
    Last edited by speghettiCode; 01-26-2012 at 10:15 AM.

  6. #6
    Join Date
    Dec 2011
    Centurion, South Africa
    I have passed back the responseText and the actual request object if you needed to retrieve more information from it. If you never do then you can remove it.

    You don't need to worry about how loadXMLDoc executes your callback, it will always be the function you passed to it at the time.
    Because f is a parameter of the function, it is basically the same as declaring it locally with var as well. Likewise for all the other declared variables.

    The problem with how you had it previously was that you were refering to the xmlhttp object in the callback, which would not have been accessible if it was declared properly.
    Last edited by bionoid; 01-26-2012 at 10:24 AM.
    JavaScript: Learn | Validate | Compact | bionoid

  7. #7
    Join Date
    Sep 2008
    awesome! Thanks very much for your help!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center



X vBulletin 4.2.2 Debug Information

  • Page Generation 0.10412 seconds
  • Memory Usage 2,908KB
  • Queries Executed 15 (?)
More Information
Template Usage (33):
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_global_above_footer
  • (1)ad_global_below_navbar
  • (1)ad_global_header1
  • (1)ad_global_header2
  • (1)ad_navbar_below
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)ad_thread_first_post_content
  • (1)ad_thread_last_post_content
  • (2)bbcode_code
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)headinclude_bottom
  • (7)memberaction_dropdown
  • (1)navbar
  • (4)navbar_link
  • (1)navbar_moderation
  • (1)navbar_noticebit
  • (1)navbar_tabs
  • (2)option
  • (7)postbit
  • (7)postbit_onlinestatus
  • (7)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available (6):
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files (26):
  • ./showthread.php
  • ./global.php
  • ./includes/class_bootstrap.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/functions_navigation.php
  • ./includes/class_friendly_url.php
  • ./includes/class_hook.php
  • ./includes/class_bootstrap_framework.php
  • ./vb/vb.php
  • ./vb/phrase.php
  • ./includes/functions_facebook.php
  • ./includes/functions_calendar.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_notice.php
  • ./packages/vbattach/attach.php
  • ./vb/types.php
  • ./vb/cache.php
  • ./vb/cache/db.php
  • ./vb/cache/observer/db.php
  • ./vb/cache/observer.php 

Hooks Called (70):
  • init_startup
  • friendlyurl_resolve_class
  • init_startup_session_setup_start
  • database_pre_fetch_array
  • database_post_fetch_array
  • init_startup_session_setup_complete
  • global_bootstrap_init_start
  • global_bootstrap_init_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • load_show_variables
  • load_forum_show_variables
  • global_state_check
  • global_bootstrap_complete
  • global_start
  • style_fetch
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • strip_bbcode
  • friendlyurl_clean_fragment
  • friendlyurl_geturl
  • forumjump
  • cache_templates
  • cache_templates_process
  • template_register_var
  • template_render_output
  • fetch_template_start
  • fetch_template_complete
  • parse_templates
  • fetch_musername
  • notices_check_start
  • notices_noticebit
  • process_templates_complete
  • friendlyurl_redirect_canonical
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • memberaction_dropdown
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • build_navigation_data
  • build_navigation_array
  • check_navigation_permission
  • process_navigation_links_start
  • process_navigation_links_complete
  • set_navigation_menu_element
  • build_navigation_menudata
  • build_navigation_listdata
  • build_navigation_list
  • set_navigation_tab_main
  • set_navigation_tab_fallback
  • navigation_tab_complete
  • fb_like_button
  • showthread_complete
  • page_templates