From user-return-5900-apmail-couchdb-user-archive=couchdb.apache.org@couchdb.apache.org Sun Aug 09 19:13:00 2009 Return-Path: Delivered-To: apmail-couchdb-user-archive@www.apache.org Received: (qmail 10180 invoked from network); 9 Aug 2009 19:13:00 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 9 Aug 2009 19:13:00 -0000 Received: (qmail 84517 invoked by uid 500); 9 Aug 2009 19:13:06 -0000 Delivered-To: apmail-couchdb-user-archive@couchdb.apache.org Received: (qmail 84435 invoked by uid 500); 9 Aug 2009 19:13:06 -0000 Mailing-List: contact user-help@couchdb.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: user@couchdb.apache.org Delivered-To: mailing list user@couchdb.apache.org Received: (qmail 84425 invoked by uid 99); 9 Aug 2009 19:13:06 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 09 Aug 2009 19:13:06 +0000 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of hallettj@gmail.com designates 209.85.217.209 as permitted sender) Received: from [209.85.217.209] (HELO mail-gx0-f209.google.com) (209.85.217.209) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 09 Aug 2009 19:12:55 +0000 Received: by gxk5 with SMTP id 5so3621971gxk.11 for ; Sun, 09 Aug 2009 12:12:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :from:date:message-id:subject:to:content-type :content-transfer-encoding; bh=GdrBwSeIG7G7sz/YLl5yZq3o5RQ6wLFn3ftIh2SWoNs=; b=GoN28V4A76sUKgHiBoOyvqM16E/8WbHAOwA55K1yv51E20lu6Yh/IIWl7TaBSCXCux K3pWN6foFltfqwmtq6gENZVoEdN4GTEHl3HXt3d9727wKyZ1ePnOmJ1F4BwlMVMn5UIz pT+IZCUSFkj5/4VhZgjI/Nq95UaQkVfBEapcY= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type:content-transfer-encoding; b=JrsyYkcQForMkNBACA5cWRaPA/7iO1kLXxmafFF0FQl5vpbag/sv2bWC4tw701ATPo ONW5SaZBeWKpi8ouzpgsdfaW04StWsfzmaXc9T5Umg5+TgBdNtlfMtyRFuUQ+x77zVym rGg+r/Cl9TXuc1FDVIDorns3OccYNMPCRNBNk= MIME-Version: 1.0 Received: by 10.150.143.7 with SMTP id q7mr6687392ybd.175.1249845154111; Sun, 09 Aug 2009 12:12:34 -0700 (PDT) In-Reply-To: References: <4A7E4D47.9010109@borwankar.com> From: Jesse Hallett Date: Sun, 9 Aug 2009 12:12:14 -0700 Message-ID: <8a02878f0908091212q7a395b74t974a4dcfca16d4b3@mail.gmail.com> Subject: Re: JSONP callback param with couchdb -lucene To: user@couchdb.apache.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Virus-Checked: Checked by ClamAV on apache.org On Sun, Aug 9, 2009 at 10:24 AM, David Nolen wrote: > The callback > function must be available in the global scope for JSONP to work correctl= y. > David > > On Sun, Aug 9, 2009 at 12:15 AM, Nitin Borwankar wro= te: > >> >> Hi all, >> >> Need some help with the cdb-luc and jQuery integration. >> >> I want to transform the results format from cdb-luc to a format that my = app >> likes. I want to do that via the JSONP callback param and some jquery >> hoop-jumping. =A0 Am curious if the syntax is as follows or something el= se:- >> >> .....?q=3Dsomequerytext&callback=3Dsomefuncname >> >> >> then inside $.ajax() I would have >> >> { >> =A0url: =A0?q=3Dsomequerytext&callback=3Dsomefuncname >> =A0[....] >> =A0dataType: "json", >> =A0contentType: "application/json" >> =A0[...] >> =A0success: =A0 =A0 somefuncname(data) { get data and transform it into = something >> recognizable to my app, do something with it } ; >> =A0error: =A0 =A0 =A0 =A0 complain(){....} >> >> } >> >> >> etc. and then the cdb-luc results will be magically stuffed into somefun= c() >> as data >> >> Is this the right syntax for the ?q =3D part for all that to happen - >> basically just macth the name in the callback param with the actual name= in >> the success: param in $.ajax() ? >> >> Has anyone used the callback param sucessfully ? Since it looks like you are using jQuery, the `$.getJSON` helper will handle JSONP for you automatically. Just pass the target URL as the first argument, and the callback function as the third argument. In the URL include a `callback` parameter with a question mark as its value. $.getJSON('?q=3Dsomequerytext&callback=3D?', null, function(data) { get data and transform it into something recognizable to my app, do something with it }); Behind the scenes jQuery will assign your function callback to a variable in the global namespace and will replace the question mark in the callback parameter with the same variable name. It will also transform the request into a script tag instead of using XMLHttpRequest. And yes, you do have the correct syntax for the URL query string.