Early Bird Registration for DrupalCon Portland 2024 is open! Register by 23:59 PST on 31 March 2024, to get $100 off your ticket.
Hello,
I'm writing a module mostly based on javascript & json and call to Drupal.parseJson a lot. Normally, Drupal.parseJson works fine for all parts of the module but does not work correctly in a page. It always return an object with 2 properties, status and data, no matter what the input string is. The 'status' property contains nothing(according to my test) and 'data' contains the input string. Then, I use eval() instread of Drupal.parseJson and everything works as normal. I'm busy now, so don't have time to put my hand on it.
Comment | File | Size | Author |
---|---|---|---|
#6 | parsejson.patch | 725 bytes | casey |
#4 | parseJson.patch | 1.61 KB | marcingy |
Comments
Comment #1
Chill35 CreditAttribution: Chill35 commentedDrupal.parseJson is deprecated in Drupal 6. Please use the jQuery function getJSON instead.
The documentation says that Drupal.parseJSON has been removed, while it is still available... http://drupal.org/node/114774
I say we get rid of the only place left in core where Drupal.parseJSON is *still* used, on line 84 of ahah.js.
I also say we add something to the header comment to say that Drupal.parseJSON is indeed deprecated, in drupal.js, with a reference to the jQuery doc page on jQuery.getJSON. Like so:
Comment #2
Gábor HojtsyYes, looks like it is not deprecated just yet:
It would be a good idea to
(1) Remove this function in Drupal 7 and eliminate it from ahah.js
(2) Backport the elimination and add a depreciation note to drupal.js
Retitled and reversioned according to this.
Comment #3
casey CreditAttribution: casey commentedDrupal.parseJson() still exists and is still being used in (renamed) ajax.js
Comment #4
marcingy CreditAttribution: marcingy commentedInitial patch to get this rolling
Comment #5
c960657 CreditAttribution: c960657 commentedHow did you test this? When is the response variable a string?
AFAICT jQuery.getJSON() isn't a drop-in replacement for Drupal.parseJson(). jQuery.getJSON() should be called with a URL and it then does a HTTP request. Drupal.parseJson() simply parses a JSON string.
http://docs.jquery.com/Ajax/jQuery.getJSON
Comment #6
casey CreditAttribution: casey commentedLike @c960657 said in #5: Drupal.parseJson() isn't same as jQuery.getJSON(), so we shouldn't replace it.
We can however optimize it. Patch uses Native JSON parser when available (FF and IE8). jQuery 1.4 is parsing json the same way as this patch.
Comment #7
casey CreditAttribution: casey commentedNew issue for that patch: #673884: Optimize Drupal.parseJSON
Comment #8
btully CreditAttribution: btully commentedsubscribe