Blog » Minor API Change in 1.0.2
Posted October 13th, 2006 by John ResigI forgot to mention in the 1.0.2 release notes, the other day, that there was a minor API change. This was a mistake, as we should’ve held off on making an API change until the next major release (jQuery 1.1).
As summarized by Steven Wittens, here is the premise behind the change:
In jQuery 1.0.2, the first argument to the ’success’ callback has been changed to return the actual data rather than the XMLHttpRequest object. Use the ‘dataType’ argument to $.ajax() to control how the data is returned. Note that jQuery can now parse XML, JSON and JavaScript for you this way.
jQuery 1.0.1
$.ajax( {
success: function (xmlhttp) {
var data = $.httpData( xmlhttp );
// 'data' holds the response data from the server
}
);
jQuery 1.0.2
$.ajax( {
success: function (data) {
// 'data' holds the response data from the server
}
);
Thanks, Steven, for the synopsis - and sorry, everyone, for the inconvenience!
October 14th, 2006 at 6:29 am
Wow that’s great!
The other day I was wondering why it returned the ‘XMLHttpRequest object’ because the response data would have made more sense.
October 14th, 2006 at 8:13 am
[…] update : jQuery 的官方部落格今天提到了這點:其實這項 API 的變動,原本是預計等到 1.1 版的 major release 時才會變更的,結果「不小心」在 1.0.2 時就先用了,然後又順便忘了提到這點…… […]
October 15th, 2006 at 12:29 am
Oh man! I suffered with this!
Thanks!
I gave up and returned to the precedent release.
Now happy to see what happened
October 18th, 2006 at 2:51 pm
I am really sorry for posting this here but I could not find a way to post something to this Bug Tracker and I may care for jQuery but I am not the mailing list guy, so I’d liek to just report this: while the .ready() works fine in the online version of my site under Opera 9 (latest build), on my local version (running on apache) it fails badly when a page is reloaded but works for the first time the page is accessed. The weird thing is that it returns no erros in the Error Console.Note that this only happens in Opera. Maybe someone could look at it?
Thank you in advance.
October 25th, 2006 at 7:23 am
Well I noticed there was a change. This particularily affects the progressive enhancement article, as often if using json as the type, it’s difficult to always get the server response exactly what you want it before you lock into json. Sometimes i’ll dump a variable out in non json format. Then everything broke. I modified jq-latest for this:.
{{{
[code]
httpData: function(r,type) {
var ct = r.getResponseHeader(”content-type”);
var data = !type && ct && ct.indexOf(”xml”) >= 0;
data = type == “xml” || data ? r.responseXML : r.responseText;
// If the type is “script”, eval it
if ( type == “script” ) eval.call( window, data );
// Get the JavaScript object, if JSON is used.
if (type == “json”) {
alert(”Data returned: “+data);
try {
eval( “data = ” + data );
}
catch(e) {
alert(”Error on JSON Evaluation:”+e.message);
}
}
//if ( type == “json” ) eval( “data = ” + data );
return data;
}
[/code]
}}}
October 26th, 2006 at 1:14 pm
That’s nice but must be alternative-I want not string but genuine XmlHttp object,particularly if I work with xml data in some cases.How about $(”?”,xml.responseXml)?What if I need to transform data or store data in xml document format(for future reference using $() function)?Reparsing?
How I can get back previous behavior?Or we all work with strings from now?XmlHttp object contains much more information than data itself and it must be accessible IMHO(just in case for more advanced development).
Regards.
February 19th, 2007 at 4:11 am
Administrare server
June 20th, 2007 at 8:11 pm
Hello! Good Site! Thanks you! ieqhsprevsd