UPDATE 1: I haven't figured out what's going on, but this definitely seems to be a problem with my project. After creating a simple test page, I was able to verify that getJSON does in fact return an XHR object like it's supposed to.
UPDATE 2: Wow, this is strange. After doing more testing, I discovered that if I specify the "callback=?" parameter in the URL string the XHR object IS NOT RETURNED properly. If, however, I don't specify the "callback=?" parameter, the XHR object is returned properly. The thing is, I'm calling a JSONP service, so the "callback=?" parameter is required.
Any ideas about why this would be the case?
UPDATE 3: Here are a few standalone code samples to illustrate the issue. In the first sample, console.log(request) is undefined. When I hardcode the callback parameter in the second code sample, console.log(request) is the XHR object.
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
</head>
<body>
<script>
$(document).ready(function() {
var request = $.getJSON('http://localhost?callback=?', function(data) {
});
console.log(request);
});
</script>
</body>
</html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
</head>
<body>
<script>
$(document).ready(function() {
var request = $.getJSON('http://localhost?callback=callback', function(data) {
});
console.log(request);
});
</script>
</body>
</html>
UPDATE 4: Per regilero's comment below, I switched over to using the $.ajax method and passed the parameters up via a data object. Here is the full code for the request:
var request = $.ajax({
data: {
f: 'json',
geometry: '{x:44.203642291681845,y:-95.79085806500001}',
geometryType: 'esriGeometryPoint',
imageDisplay: '727,500,96',
layers: 'all',
mapExtent: '-179.462733065,16.116769346042226,-51.669764315000016,71.57609342040729',
returnGeometry: false,
tolerance: 10
},
dataType: 'jsonp',
success: function(data) {
console.log(data);
},
url: 'http://server.arcgisonline.com/ArcGIS/rest/services/Specialty/Soil_Survey_Map/MapServer/identify'
});
console.log(request);
If I specify "dataType: 'jsonp'" in the config object, console.log(request) is again undefined. If I specify "dataType: 'json'", however, console.log(request) is the XHR object.
This behavior is consistent with what I was experiencing with the $.getJSON shortcut.
ORIGINAL QUESTION
Per the stackoverflow question/answer here: Abort Ajax requests using jQuery and a number of other question/answers on this site and others, the jQuery Ajax methods should return the XHR object.
However, when I run the following code, request is "undefined".
var request = $.getJSON(url, function(data) {
console.log(data);
});
console.log(request);
Did I miss a change in jQuery? I'm using 1.4.4.