Side navigation
#15118 closed bug (fixed)
Opened May 29, 2014 04:31PM UTC
Closed June 02, 2014 08:40PM UTC
Error using "jquery/ajax" with AMD
Reported by: | tj.vantoll | Owned by: | |
---|---|---|---|
Priority: | low | Milestone: | 1.12/2.2 |
Component: | ajax | Version: | 1.11.1 |
Keywords: | Cc: | ||
Blocked by: | Blocking: |
Description
I'm trying to create snippets of how to use pieces of jQuery outside of the whole library. For a basic AJAX call I'm attempting to use the following:
define([ "jquery/ajax" ], function( $ ) { $.ajax( "http://whatever" ); });
But I get an error on this line because
jQuery.eventis undefined. If I use this block the call works:
define([ "jquery/event", "jquery/ajax/xhr" ], function( $ ) { $.get( "http://whatever" ); });
So my question is: should ajax.js depend on event.js?
Attachments (0)
Change History (5)
Changed May 29, 2014 05:29PM UTC by comment:1
milestone: | None → 1.12/2.2 |
---|---|
priority: | undecided → low |
status: | new → open |
Changed May 29, 2014 05:50PM UTC by comment:2
I verified that setting
globalto
falseavoids this problem.
This is tricky, but I think a quick check for
jQuery.eventis a good idea. 99.9% of people are not micromanaging Core, and for those that are, it'd be nice to see
$.ajaxstreamlined (and small in terms of bytes).
I'll put a PR together.
Changed May 29, 2014 05:58PM UTC by comment:3
I think it's a really quick extra conditional to where we set fireGlobals
Ugh. Well technically yes, you need event. However I think all the event work it does is guarded by the
global
option which defaults totrue
. So if you pass inglobal: false
it won't try to trigger ajax events.It seems like one solution here would be to check for
jQuery.event
and skip firing global events if it's not defined. There can't possibly be anyone listening for the event if that's the case, right?