CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • API explorer and generator - javascript error - $ is not a function
Pages: [1]

Author Topic: API explorer and generator - javascript error - $ is not a function  (Read 1942 times)

michaellenahan

  • I post occasionally
  • **
  • Posts: 30
  • Karma: 0
    • mick.appspot.com
API explorer and generator - javascript error - $ is not a function
May 30, 2011, 10:30:46 am
Hello there,

I'm playing with the amazing v3 api.

On my local ubuntu 11.04 machine, I set up a new drupal 7.2 + civicrm-4.0.1 at: http://learncivi.local

When I go to: http://learncivi.local/civicrm/ajax/doc#explorer I get the API explorer and generator page.

The problem is that the results of the api call are not showing in the grey area.

On Firefox, the error console (ctrl+alt+j) reports this error:
$ is not a function

Similarly Chromium reports:
Uncaught TypeError: Property '$' of object [object DOMWindow] is not a function

the offending line in both cases is:
var version = $('#version').val();
... which is the first line of: function generateQuery ()

jQuery seems to work fine elsewhere within civicrm (datepicker and so on).

One thing I noticed was that when I go to the civicrm home page:
http://learncivi.local/civicrm
... I have as expected the civicrm administration toolbar, with the search box top-left.

But when I go to: http://learncivi.local/civicrm/ajax/doc#explorer
... the civicrm administration toolbar is replaced with the drupal 7 admin toolbar. Don't know if that's relevant.

Settings:
http://learncivi.local/civicrm/admin/setting/url?reset=1
CiviCRM resource URL = http://learncivi.local/sites/all/modules/civicrm

for what it's worth, the demo in civi 3.4 ...
http://drupal.demo.civicrm.org/civicrm/ajax/doc#explorer
... works fine on both browsers

any ideas?

thanks, Michael
« Last Edit: May 30, 2011, 10:40:55 am by michaellenahan »

Hershel

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4640
  • Karma: 176
    • CiviHosting
  • CiviCRM version: Latest
  • CMS version: Mostly WordPress and Drupal
Re: API explorer and generator - javascript error - $ is not a function
May 30, 2011, 10:46:31 am
I see this same issue on another site and on the D7 demo: http://d7.sandbox.civicrm.org/civicrm/ajax/doc#explorer

I reported this bug in the Issue Tracker here: http://issues.civicrm.org/jira/browse/CRM-8233

Thank you for the report.
CiviHosting and CiviOnline -- The CiviCRM hosting experts, since 2007

See here for the official: What to do if you think you've found a bug.

michaellenahan

  • I post occasionally
  • **
  • Posts: 30
  • Karma: 0
    • mick.appspot.com
Re: API explorer and generator - javascript error - $ is not a function
May 30, 2011, 12:49:04 pm
Thanks for confirming and filing the bug report Hershel. I should have noticed the D7 sandbox!
Michael

michaellenahan

  • I post occasionally
  • **
  • Posts: 30
  • Karma: 0
    • mick.appspot.com
Re: API explorer and generator - javascript error - $ is not a function
May 31, 2011, 08:58:43 am
On investigation the issue looks like a conflict in jQuery - the $ sign is not recognised when jQuery is used for multiple purposes on a site.

I noticed that in the head of the page, near the bottom a variable cj is set like this:
var cj = jQuery.noConflict(true);

... and that cj can be used further on in place of the $ sign where the $ sign is not being recognised.

I got civicrm/ajax/doc#explorer working on my local machine by replacing $ with cj in the generateQuery and runQuery functions.

Here's a link to a discussion along the same lines about jQuery issues:
http://forum.civicrm.org/index.php?topic=8977.0

Here's a patch, just for the Drupal 7 version because everything seems OK with the Drupal 6 version.

It's my first patch so feedback would be helpful if anything's not right.

Michael

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: API explorer and generator - javascript error - $ is not a function
May 31, 2011, 10:25:26 am
Hi,

Interesting, in D6, you had a $ = cj, somewhere, and the two versions (drupal and civi) were fighting, but at least one was providing cj.

Anyway, have you tried your patch on a D6 ? seems simple and make sense. will try to find the time to test on D6 and push if it works.

Thanks

X+
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

michaellenahan

  • I post occasionally
  • **
  • Posts: 30
  • Karma: 0
    • mick.appspot.com
Re: API explorer and generator - javascript error - $ is not a function
May 31, 2011, 11:49:48 am
Hi Xavier

I just applied the patch to drupal 6.22/civicrm 3.41 and the API explorer works fine.

Michael

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: API explorer and generator - javascript error - $ is not a function
June 08, 2011, 02:18:26 pm
http://issues.civicrm.org/jira/browse/CRM-8233

Could you try this patch and confirm it works?

X+
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • API explorer and generator - javascript error - $ is not a function

This forum was archived on 2017-11-26.