Bug Tracker

Opened 8 years ago

Closed 8 years ago

#15118 closed bug (fixed)

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:


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.event is 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?

Change History (5)

comment:1 Changed 8 years ago by dmethvin

Milestone: None1.12/2.2
Priority: undecidedlow
Status: newopen

Ugh. Well technically yes, you need event. However I think all the event work it does is guarded by the global option which defaults to true. So if you pass in global: 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?

comment:2 Changed 8 years ago by tj.vantoll

I verified that setting global to false avoids this problem.

This is tricky, but I think a quick check for jQuery.event is a good idea. 99.9% of people are not micromanaging Core, and for those that are, it'd be nice to see $.ajax streamlined (and small in terms of bytes).

I'll put a PR together.

comment:3 Changed 8 years ago by dmethvin

I think it's a really quick extra conditional to where we set `fireGlobals`

comment:5 Changed 8 years ago by TJ VanToll

Resolution: fixed
Status: openclosed

Ajax: Support usage without jQuery.event

Fixes #15118 Closes gh-1588

Changeset: d41e81980ea89e56c04eb14d8c27f4692b367604

Note: See TracTickets for help on using tickets.