sleepy mongoose js ajax calls

250 views
Skip to first unread message

john.tiger

unread,
Nov 28, 2012, 1:04:36 AM11/28/12
to mongod...@googlegroups.com
we've tried to write some ajax calls for sleepy mongoose (see below) -
if we paste the criteria code into a curl command - it runs fine.
however as a ajax call it is not working - any help on this ?

function get_user(db,collection,username,password){
var db = "testdb";
var coll = "users";
var criteria = "?criteria=%7B%22username%22%3A%22"+username+
"%22%2C%22password%22%3A%22"+password+"%22%7D";
var query_url = "http://127.0.0.1:27080/"
+db+"/"+coll+"/_find"+criteria;
alert("query url "+query_url)
$.ajax({
url: query_url,
type: "GET",
dataType: "jsonp",
success: function(data){
alert("success get data "+JSON.stringify(data.results));
return data.results;
}
});
}


$("#login_submit").on("click", function(){
//alert("login");
var user_doc = {};
var form = $(event.target).parents("form#login_form");
var login_doc = login_form_to_doc(null,form);
//alert("form "+ JSON.stringify(login_doc));
user_doc = get_user("testdb", "users",
login_doc.username, login_doc.password);
alert("user from login "+JSON.stringify(user));
if (!user_doc) {
alert("Login + Password Failed");
hidePages();
$("#index_page").show();
return false;
} else {
set_session(user_doc);
alert("session "+ session.username);
hidePages();
$("#index_page").show();
return false;
}

Kristina Chodorow

unread,
Dec 7, 2012, 2:54:14 PM12/7/12
to mongod...@googlegroups.com
Can you try passing in criteria with the data field?  It might be doing some escaping on the URL.

Tiger Nassau Inc

unread,
Dec 6, 2012, 5:06:05 PM12/6/12
to mongod...@googlegroups.com
No luck
I changed the ajax function to
dataType:"json",
data: criteria,

The mongo log does not show the ajax function firing
Sent from my LG Mobile

Kristina Chodorow <kris...@10gen.com> wrote:

>--
>You received this message because you are subscribed to the Google
>Groups "mongodb-user" group.
>To post to this group, send email to mongod...@googlegroups.com
>To unsubscribe from this group, send email to
>mongodb-user...@googlegroups.com
>See also the IRC channel -- freenode.net#mongodb

Kristina Chodorow

unread,
Dec 7, 2012, 5:13:47 PM12/7/12
to mongod...@googlegroups.com
Can you catch failure as well as success?  See what the error is?

Tiger Nassau Inc

unread,
Dec 7, 2012, 9:44:29 AM12/7/12
to mongod...@googlegroups.com
ReadyState 0
ResponseText ""
Status 0
StatusText "error"

mongo log connection acceptrd from 127.0.0.1:41844 #1

Any guesses?

Sent from my LG Mobile

Kristina Chodorow <kris...@10gen.com> wrote:

>Can you catch failure as well as success? See what the error is?
>
>On Thursday, December 6, 2012 5:06:05 PM UTC-5, john tigernassau wrote:
>>
>> No luck
>> I changed the ajax function to
>> dataType:"json",
>> data: criteria,
>>
>> The mongo log does not show the ajax function firing
>> Sent from my LG Mobile
>>

>> >To post to this group, send email to mongod...@googlegroups.com<javascript:>


>> >To unsubscribe from this group, send email to

>> >mongodb-user...@googlegroups.com <javascript:>

Prashanta Sharma

unread,
Feb 8, 2017, 7:25:06 AM2/8/17
to mongodb-user, john.tig...@gmail.com
I am tryring to execute in sleepy mongoose ::   curl -X GET 'http://localhost:27080/regiondb/regioncol/_find?criteria=%7B%22RegionName%22%3A/%5EIn/%7D'
 
but getting following error::

{"ok" : 0, "errmsg" : "couldn't parse json: {"RegionName":/^In/}"}

please help::

Finally I have to execute the followinf query::   db.regioncol.find({RegionName:{ $regex:/^In/}},{RegionName:1,_id:0})


with regards,
Prashanta
Reply all
Reply to author
Forward
0 new messages