couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Nitin Borwankar <ni...@borwankar.com>
Subject Re: callback=? parameter expected by jQuery $.ajax() causes couch to complain about bad URL
Date Sun, 02 Aug 2009 07:26:23 GMT
Nitin Borwankar wrote:
>
> $.get("http://localhost:5984/", function(data){ alert(data.version); 
> }, "json" );
> $.get("http://localhost:5984/", function(data){ 
> alert(data['version']); }, "json" );
>
> these give an alert that says "undefined".
>
> I have just been unable to get the browser to interpret the response 
> from couch as "json".


OK, finally success.  I set the type to "json" and did a 
JSON.parse(data) on the data passed into the callback.
It seems strange that this has to be explicitly done.  This appears to 
be a content tye issue.  I debugged this using curl -v more below.


This is what worked

include the  script
      <script src="/_utils/script/json2.js"></script>
amongst others

$.get("http://localhost:5984/", function(data){ 
alert(JSON.parse(data)['version']); }, "json" );

this gives an alert with 0.9.0 as expected.

So the major hurdle has been cleared.

Paul many thanks again for your patience.

Here's what I saw using curl -v pointing to just the base url for couchdb

curl -v $CDBA

* About to connect() to localhost port 5984 (#0)
*   Trying 127.0.0.1... connected
* Connected to localhost (127.0.0.1) port 5984 (#0)
* Server auth using Basic with user 'nitin'
 > GET / HTTP/1.1
 > Authorization: Basic bml0aW46bjF0MW4=
 > User-Agent: curl/7.19.3 (i386-apple-darwin9.6.0) libcurl/7.19.3 
zlib/1.2.3
 > Host: localhost:5984
 > Accept: */*
 >
< HTTP/1.1 200 OK
< Server: CouchDB/0.9.0 (Erlang OTP/R12B)
< Date: Sun, 02 Aug 2009 07:22:21 GMT
< Content-Type: text/plain;charset=utf-8       <------------ note couch 
is returning a text/plain rather than application/json
< Content-Length: 40
< Cache-Control: must-revalidate
<
{"couchdb":"Welcome","version":"0.9.0"}
* Connection #0 to host localhost left intact
* Closing connection #0

Not sure if there's a reason for this or this could be legitimately 
changed in 0.10

Nitin






Nitin



>
>
> Nitin
>
>> Paul
>>
>>  
>>> Nitin
>>>    
>>>> Then you can just make AJAX call's directly from the page without
>>>> worrying about the callback parameter at all. This is probably what
>>>> you want.
>>>>
>>>> If not, then you'll need to upgrade.
>>>>
>>>> HTH,
>>>> Paul Davis
>>>>
>>>>
>>>>      
>>>>>> HTH,
>>>>>> Paul Davis
>>>>>>
>>>>>>
>>>>>>
>>>>>>          
>>>>>>>            
>>>>>>>> Paul
>>>>>>>>
>>>>>>>> On Sat, Aug 1, 2009 at 10:43 PM, Nitin 
>>>>>>>> Borwankar<nitin@borwankar.com>
>>>>>>>> wrote:
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>              
>>>>>>>>> Paul Joseph Davis wrote:
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>                
>>>>>>>>>> Ntitn,
>>>>>>>>>>
>>>>>>>>>> Are you on couchdb trunk? Pretty sure jsonp was after
0.9.
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>                   
>>>>>>>>> Hey Paul,
>>>>>>>>>
>>>>>>>>> Thanks much
>>>>>>>>>
>>>>>>>>> I am on couchdbx 0.9 on leopard 10.5.7
>>>>>>>>>
>>>>>>>>> Is jsonp in 0.9.1 ?  That would be motivation for me
to move.
>>>>>>>>>
>>>>>>>>> Also assuming the answer is yes - in the new improved
couch - 
>>>>>>>>> do I
>>>>>>>>> just
>>>>>>>>> use
>>>>>>>>> the callback=? on the client request or do I have to
do 
>>>>>>>>> something in
>>>>>>>>> my
>>>>>>>>> views to set content-type? as well.
>>>>>>>>>
>>>>>>>>> Thanks much,
>>>>>>>>>
>>>>>>>>> Nitin
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>                
>>>>>>>>>> Paul Davis
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> On Aug 1, 2009, at 9:57 PM, Nitin Borwankar 
>>>>>>>>>> <nitin@borwankar.com>
>>>>>>>>>> wrote:
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>                  
>>>>>>>>>>> Hello all,
>>>>>>>>>>>
>>>>>>>>>>> I  have been banging my head against this wall
for 2 days and I
>>>>>>>>>>> finally
>>>>>>>>>>> made
>>>>>>>>>>> a crack ---
>>>>>>>>>>>
>>>>>>>>>>> Trying to use jQuery, $.ajax()  in an app that
calls couchdb 
>>>>>>>>>>> api -
>>>>>>>>>>> not
>>>>>>>>>>> using
>>>>>>>>>>> ( cannot use ) couchapp must call from legacy
app.
>>>>>>>>>>> Couldn't get a successful response.
>>>>>>>>>>>
>>>>>>>>>>> finally just put the get query into firefx and
go the following
>>>>>>>>>>> which
>>>>>>>>>>> explains why it's not working - but not a clue
how to work 
>>>>>>>>>>> around
>>>>>>>>>>> this.
>>>>>>>>>>>
>>>>>>>>>>> get query:
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>> http://localhost:5984/ptest2/_design/vt2/_view/tag?group=true&limit=5&callback=

>>>>>>>>>>>
>>>>>>>>>>> ?
>>>>>>>>>>> couch responds: {"error":"query_parse_error","reason":"Bad
URL
>>>>>>>>>>> query
>>>>>>>>>>> key:callback"}
>>>>>>>>>>>
>>>>>>>>>>> I don't have the option to use either couch.js
or 
>>>>>>>>>>> jquery.couch.js
>>>>>>>>>>> but
>>>>>>>>>>> have
>>>>>>>>>>> to use vanilla jQuery ajax calls $.get, $.ajax,
$.post, 
>>>>>>>>>>> $,getJSON
>>>>>>>>>>> etc.
>>>>>>>>>>>
>>>>>>>>>>> Am I stuck without any help possible ?
>>>>>>>>>>>
>>>>>>>>>>> Nitin
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>> 37% of all statistics are made up on the spot
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>> -------------------------------------------------------------------------------------

>>>>>>>>>>>
>>>>>>>>>>> Nitin Borwankar
>>>>>>>>>>> nborwankar@gmail.com
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>                     
>>>>>>>>>                 
>>>>>>>             
>>>>>         
>>>     
>


Mime
View raw message