Can Ajax events be sub events?

  • Was watching my code in the debugger. I have several Ajax events that keep firing even when there's no Ajax request being sent. So, I thought I'd streamline things a bit and create an Ajax On Any Completed and then, move all of my Ajax On Completed events under it. That way, the code isn't constantly checking half a dozen events and is instead, checking just one.

    Well, I was surprised to find out that I can't make an Ajax event a sub event.

    So, I thought I'd be clever. I'd create a function and On Any Completed, I'd call the function to see which Ajax event completed. Wrong. Apparently you can't even make any Ajax event part of a function.

  • You can use sub-events or even a function to trigger specific behavior according to which AJAX requested was completed.

    The single entry point must be "On any completed", but after that, you need to check the AJAX.Tag expression to identify which request it was.

  • Ok, that makes sense. I was trying to put an Ajax on event inside another ajax on event.

    Thanks.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Yes, that's why it didn't work. And also, this is a shared behavior of all triggers, they cannot be nested, which, as you said, wouldn't make sense if they could.

  • Yep, took your suggestion, made one catchall event and checked the tag. Worked great.

    But, as it turns out, that wasn't the cause of all the checks going on. It was JSON checks for keys. Unfortunately, there doesn't seem to be an onParsed event for JSON. So I'm checking every cycle to see if any of several keys exist which only exist when the Ajax gets a response and then, I have to delete the key to keep them from being true every cycle.

    Thanks again though.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)