简体   繁体   中英

Why is jQuery.getJSON structured the way it is?

Why is the getJSON function structured this way?

 $.getJSON( url [, data ] [, success ] )

Instead of just returning an object, ie:

 var myjson = $.getJSON( url [, data ])

Because it returns a jqXHR object that contains responseText and responseXML properties, as well as a getResponseHeader() method. When the transport mechanism is something other than XMLHttpRequest (for example, a script tag for a JSONP request) the jqXHR object simulates native XHR functionality where possible. Basically, how would you know if the request was successful?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM