Skip to content Skip to sidebar Skip to footer

Jquery.ajax() Makes A Copy Of The Settings Object?

JQuery.ajax() accepts a settings argument. The functions for success or error (for example) run in the context of this object. var arr = []; var a = { url : '/', arbiterary

Solution 1:

Yes, jQuery creates a new options object when you call jQuery.ajax(). The result is a combination of the settings object you passed and the global jQuery.ajaxSettings object, so that you have the correct default values and any settings you've set globally, even when you don't explicitly set them in the object passed.

This can be seen in the source code for jQuery 1.9 on line 7745:

// Create the final options object
s = jQuery.ajaxSetup( {}, options ),

Generally you use the context property to specify a different value for this inside the callback functions, so:

options= {
    url:'/',
    ...,
    context:a
}

However, the circular reference in your case (a referring to itself in one of its properties) may cause issues if the merge does a deep copy.

Post a Comment for "Jquery.ajax() Makes A Copy Of The Settings Object?"