[web2py] Re: Ajax function

2013-11-13 Thread Derek
You're using eval, but are you returning executable javascript from your 
function 'paginatore' ?

On Tuesday, November 12, 2013 7:17:52 AM UTC-7, Luca Dalla Palma wrote:
>
>
> Hello,
> this is my *view*
> 
>
> on the *controller *I build a function containing the folowing code:
>
> pippone='ciao'
> stringa.append("jQuery('#paginatore').html('%s');" % pippone())
> print pippone
> return stringa
>
> The console says
>  href="#">ciao
> (the HTML generated appears to be right)
>
> When the function returns, I expect the new anchor to appear in the 
> "paginatore" div, but it doesn't. Anybody can suggest me why?
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


[web2py] Re: Ajax function and returning Row, not string

2013-06-19 Thread lesssugar
Yes, my assumption was incorrect. I thought ajax() would return a Row 
object to my ID target element, so then I could use it within the element.

"I have never been so wrong".

Well, it works now:

controller:

def rank():

ranks = db(db.rank.department_id == 
request.vars.department).select(db.rank.id, db.rank.name, 
orderby=db.rank.name)

result = ""

for r in ranks:
result += "" + r.name + 
""

return XML(result)

view:


{{if request.vars.department:}}
{{=XML(result)}}
{{pass}}


- it did the trick. The rest of the code is the same.

Cheers.


On Tuesday, June 18, 2013 8:37:00 PM UTC+2, Derek wrote:
>
> One more thing - I've seen people have issues with this time and again on 
> this list. You aren't the first person to think of doing this. Look for a 
> good recipe on web2pyslices which does what you want. There are quite a few.
>
>
> http://www.web2pyslices.com/slice/show/1467/cascading-drop-down-lists-with-ajax
>
>
> On Tuesday, June 18, 2013 10:39:51 AM UTC-7, lesssugar wrote:
>>
>> I'm building a cascading dropdown lists. I use web2py ajax function to do 
>> it. My code:
>>
>> select 1 (parent):
>>
>> > name="department" 
>> onchange="jQuery('#seafarer_experience_rank__row').show('fast');ajax('rank', 
>> ['department'], 'seafarer_experience_rank');">
>> {{=OPTION('-- Choose department --', _value="")}}
>> {{for d in departments:}}
>> {{=OPTION(d.name, _value=d.id)}}
>> {{pass}}
>> 
>>
>> select 2 (child):
>>
>> 
>> {{if request.vars.department:}}
>> {{for r in ranks:}}
>> {{=OPTION(r.name, _value=r.id)}}
>> {{pass}}
>> {{pass}}
>> 
>>
>> controller function:
>>
>> def rank():
>>
>> ranks = db(db.rank.department_id == request.vars.department).select(
>> db.rank.id, db.rank.name, orderby=db.rank.name)
>>
>> return ranks
>>
>> Ajax function calls *rank *function and passess value of the currently 
>> selected option in *department *select (parent). Then, the function 
>> assigns DAL query to *ranks *and returns it.
>>
>> The thing is that *ranks *is a string when returned and the FOR loop in 
>> the select 2 is ommited. An example result code of the select 2 looks like 
>> this after ajax function's done it's job:
>>
>> 
>> "rank.idrank.name137Chief Cook138Chief Steward139Cook 
>> Assistant140Messman136Second Cook141Steward"
>> 
>>
>> So it LOOKS like a Row object but it's a string obvioulsy - and I can't 
>> get any Row data out of it (r.name, r.id).
>>
>> Begging for help here :)
>>
>>  
>>
>>

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Re: Ajax function and returning Row, not string

2013-06-18 Thread Derek
One more thing - I've seen people have issues with this time and again on 
this list. You aren't the first person to think of doing this. Look for a 
good recipe on web2pyslices which does what you want. There are quite a few.

http://www.web2pyslices.com/slice/show/1467/cascading-drop-down-lists-with-ajax


On Tuesday, June 18, 2013 10:39:51 AM UTC-7, lesssugar wrote:
>
> I'm building a cascading dropdown lists. I use web2py ajax function to do 
> it. My code:
>
> select 1 (parent):
>
>  name="department" 
> onchange="jQuery('#seafarer_experience_rank__row').show('fast');ajax('rank', 
> ['department'], 'seafarer_experience_rank');">
> {{=OPTION('-- Choose department --', _value="")}}
> {{for d in departments:}}
> {{=OPTION(d.name, _value=d.id)}}
> {{pass}}
> 
>
> select 2 (child):
>
> 
> {{if request.vars.department:}}
> {{for r in ranks:}}
> {{=OPTION(r.name, _value=r.id)}}
> {{pass}}
> {{pass}}
> 
>
> controller function:
>
> def rank():
>
> ranks = db(db.rank.department_id == request.vars.department).select(
> db.rank.id, db.rank.name, orderby=db.rank.name)
>
> return ranks
>
> Ajax function calls *rank *function and passess value of the currently 
> selected option in *department *select (parent). Then, the function 
> assigns DAL query to *ranks *and returns it.
>
> The thing is that *ranks *is a string when returned and the FOR loop in 
> the select 2 is ommited. An example result code of the select 2 looks like 
> this after ajax function's done it's job:
>
> 
> "rank.idrank.name137Chief Cook138Chief Steward139Cook 
> Assistant140Messman136Second Cook141Steward"
> 
>
> So it LOOKS like a Row object but it's a string obvioulsy - and I can't 
> get any Row data out of it (r.name, r.id).
>
> Begging for help here :)
>
>  
>
>

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Re: Ajax function and returning Row, not string

2013-06-18 Thread Derek
Well, you're doing it wrong. 
I mean, the way you are calling the ajax function...

ajax('rank', ['department'], 'seafarer_experience_rank');

What that does is  calls 'rank' with the argument 'department' and replace 
the contents of the element whose ID is 'seafarer_experience_rank' with the 
results. In this case, it's wiping out your:
{{if request.vars.department:}}
{{for r in ranks:}}
{{=OPTION(r.name, _value=r.id)}}
{{pass}}
{{pass}}
And replacing it with the dict that is returned from 'rank'. You probably 
want the 'rank' function to return your HTML that you want.
Or you should use a javascript templating library (such as jqote2) to take 
your data (returned as a dict) and turn it into html.

On Tuesday, June 18, 2013 10:39:51 AM UTC-7, lesssugar wrote:
>
> I'm building a cascading dropdown lists. I use web2py ajax function to do 
> it. My code:
>
> select 1 (parent):
>
>  name="department" 
> onchange="jQuery('#seafarer_experience_rank__row').show('fast');ajax('rank', 
> ['department'], 'seafarer_experience_rank');">
> {{=OPTION('-- Choose department --', _value="")}}
> {{for d in departments:}}
> {{=OPTION(d.name, _value=d.id)}}
> {{pass}}
> 
>
> select 2 (child):
>
> 
> {{if request.vars.department:}}
> {{for r in ranks:}}
> {{=OPTION(r.name, _value=r.id)}}
> {{pass}}
> {{pass}}
> 
>
> controller function:
>
> def rank():
>
> ranks = db(db.rank.department_id == request.vars.department).select(
> db.rank.id, db.rank.name, orderby=db.rank.name)
>
> return ranks
>
> Ajax function calls *rank *function and passess value of the currently 
> selected option in *department *select (parent). Then, the function 
> assigns DAL query to *ranks *and returns it.
>
> The thing is that *ranks *is a string when returned and the FOR loop in 
> the select 2 is ommited. An example result code of the select 2 looks like 
> this after ajax function's done it's job:
>
> 
> "rank.idrank.name137Chief Cook138Chief Steward139Cook 
> Assistant140Messman136Second Cook141Steward"
> 
>
> So it LOOKS like a Row object but it's a string obvioulsy - and I can't 
> get any Row data out of it (r.name, r.id).
>
> Begging for help here :)
>
>  
>
>

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Re: ajax function in a grid, I'm getting None in a request.vars

2013-03-29 Thread Tim Richardson

So this works as far as getting my database update going: passing args 
constructed with the URL helper

links = [lambda row: INPUT(_name='toggle',_type="submit",_value="Toggle",
_onclick="ajax('%s','' ,':eval')" % URL(
'toggle_order_import',args=[row.id]))])


-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Re: ajax function in a grid, I'm getting None in a request.vars

2013-03-29 Thread Tim Richardson


On Saturday, 30 March 2013 16:23:26 UTC+11, Tim Richardson wrote:
>
> I'm trying to learn more about LOAD and ajax.
>
> I have an SQLFORM.grid loaded as a component. It's read only.
>

So this means the result is just an HTML table, not a form, so the field 
name is actually not there. 
looking at the ajax javascript, it seems that the second parameter can be a 
string, in which case it is serialised.
Is there a way that I can take advantage of this?

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Re: ajax() function doesn't work properly (returns parent page)

2012-05-02 Thread Anthony
Try going to http://127.0.0.1:8000/inventoryapp/default/index/ (note the 
trailing "/"), and you should see the same problem. On the storeadmin page, 
the problem should go away if you exclude the trailing "/" from the URL.

The problem is, in the call to ajax(), the URL is just 'echo'. Because it 
doesn't start with a "/", the browser interprets that as being relative to 
the current URL path, which it assumes ends after the last "/". If the 
current URL ends in a "/", the browser just adds "echo" to that and makes 
the Ajax call to the current URL (web2py will just see "echo" as a URL 
argument rather than a function). If you check the network traffic on the 
storeadmin example, you should see the Ajax call going 
to http://127.0.0.1:8000/inventoryapp/default/storeadmin/echo.

The best approach is to use the full URL in the Ajax call, using the URL() 
function:

_onkeyup="ajax(%s, ['keyword'], 'target');" % URL('default', 'echo')

We should probably change that in the book.

Anthony

On Wednesday, May 2, 2012 3:09:48 AM UTC-4, Dolgion Chuluunbaatar wrote:
>
> Hello,
> I am trying to make the echo example work which is in the online book.
> It works fine in my index function, but it doesn't work in any other 
> function.
> I use the same callback method in both views:
>
> def echo():
> return request.vars.keyword
>
>
> and the methods (one is index, the other is called storeadmin) have 
> identical code and views as well:
>
> def index(): #as well as def: storeadmin():
>
>
> return dict(
> form = FORM (
>   INPUT(
>   _name='keyword',
>   _onkeyup="ajax('echo', ['keyword'], 'target');"
>   )
>   ),
>   target_div=DIV(_id='target'))
>
>
> the view is:
>
>
> {{extend 'layout.html'}}
>
>
> {{=form}}
>
>
> 
>
>
> {{=target_div}}
>
> In index, the ajax call works as it should, but in storeadmin, I get the 
> entire page pasted into the target div.
> I put 2 screenshots of the pages for both methods to make it more clear.
>
> do you have any idea why this could be?
>
>

[web2py] Re: ajax function with eval : return js function from controller

2011-11-08 Thread Vineet
h..
Seems that I need to return js code lines (not js function) from
controller & get going ahead.
btw, I have found one line jquery code for selecting value of select
box.

"$('#element_id option[value=%s]').attr('selected', 'selected');" %
adict['key']

Thanks for your responses Anthony.

--- Vineet

On Nov 8, 7:31 pm, Anthony  wrote:
> I think you need .options[i] rather than .options(i). Anyway, it's
> generally easier to do this kind of thing with jQuery rather than raw
> Javascript.
>
> Anthony
>
>
>
> On Tuesday, November 8, 2011 9:04:41 AM UTC-5, Vineet wrote:
>
> > Something is wrong in the function.
> > I defined a test js function in View.
>
> > function alrt(mesg) {
> > alert(mesg) };
>
> > And in Controller,
> > return "alrt('Hello World!');"
>
> > It works.
>
> > The actual js function is---
> > (it sees which value of select box matches the one returned from
> > controller; then sets the value of select box to that value).
>
> > function selbx(elementID, value_returned_from_dataset){
> >             for (i=0;i >              {
> >                 if (value_returned_from_dataset ==
> > document.getElementById(elementID).options(i).text)
>
> > {document.getElementById(elementID).options(i).selected = true;
>
> >                      }}}
>
> > In controller---
> > return "selbx('id_of_element','%s');" % dict_obj['freq']
>
> > dict_obj['freq'] is non-blank.
> > It is a string itself.
> > 
> > If individual code-lines are returned, it works.
> > 
>
> > Any guess why so?
>
> > Regards,
> > Vineet
>
> > On Nov 8, 6:44 pm, Anthony  wrote:
> > > On Tuesday, November 8, 2011 8:17:41 AM UTC-5, Vineet wrote:
>
> > > > > If 'myvar' is a Python variable, you're going
>
> > > > 'myvar' is a not a python variable.
> > > > I pass the id of html element as argument.
> > > > Javascript code sets the value of that html element.
>
> > > OK, but same problem -- 'myvar1' isn't a javascript variable either --
> > it
> > > is a string identifying an html element. So you would still have to
> > return
> > > 'abc("myvar1")', or maybe 'abc("#myvar1")', depending on how you are
> > using
> > > it in the code.
>
> > > Anthony- Hide quoted text -
>
> - Show quoted text -


[web2py] Re: ajax function with eval : return js function from controller

2011-11-08 Thread Vineet
h..
Seems that I need to return js code from controller.
btw, I have found a one-line jquery code for this-->

"$('#element_id option[value=%s]').attr('selected', 'selected');" %
dict_obj['key']

This works & I will proceed with this, for time being.
Thanks for your responses Anthony.

--- Vineet

On Nov 8, 7:31 pm, Anthony  wrote:
> I think you need .options[i] rather than .options(i). Anyway, it's
> generally easier to do this kind of thing with jQuery rather than raw
> Javascript.
>
> Anthony
>
>
>
> On Tuesday, November 8, 2011 9:04:41 AM UTC-5, Vineet wrote:
>
> > Something is wrong in the function.
> > I defined a test js function in View.
>
> > function alrt(mesg) {
> > alert(mesg) };
>
> > And in Controller,
> > return "alrt('Hello World!');"
>
> > It works.
>
> > The actual js function is---
> > (it sees which value of select box matches the one returned from
> > controller; then sets the value of select box to that value).
>
> > function selbx(elementID, value_returned_from_dataset){
> >             for (i=0;i >              {
> >                 if (value_returned_from_dataset ==
> > document.getElementById(elementID).options(i).text)
>
> > {document.getElementById(elementID).options(i).selected = true;
>
> >                      }}}
>
> > In controller---
> > return "selbx('id_of_element','%s');" % dict_obj['freq']
>
> > dict_obj['freq'] is non-blank.
> > It is a string itself.
> > 
> > If individual code-lines are returned, it works.
> > 
>
> > Any guess why so?
>
> > Regards,
> > Vineet
>
> > On Nov 8, 6:44 pm, Anthony  wrote:
> > > On Tuesday, November 8, 2011 8:17:41 AM UTC-5, Vineet wrote:
>
> > > > > If 'myvar' is a Python variable, you're going
>
> > > > 'myvar' is a not a python variable.
> > > > I pass the id of html element as argument.
> > > > Javascript code sets the value of that html element.
>
> > > OK, but same problem -- 'myvar1' isn't a javascript variable either --
> > it
> > > is a string identifying an html element. So you would still have to
> > return
> > > 'abc("myvar1")', or maybe 'abc("#myvar1")', depending on how you are
> > using
> > > it in the code.
>
> > > Anthony


[web2py] Re: ajax function with eval : return js function from controller

2011-11-08 Thread Anthony
I think you need .options[i] rather than .options(i). Anyway, it's 
generally easier to do this kind of thing with jQuery rather than raw 
Javascript.

Anthony

On Tuesday, November 8, 2011 9:04:41 AM UTC-5, Vineet wrote:
>
> Something is wrong in the function. 
> I defined a test js function in View. 
>
> function alrt(mesg) { 
> alert(mesg) }; 
>
> And in Controller, 
> return "alrt('Hello World!');" 
>
> It works. 
>
> The actual js function is--- 
> (it sees which value of select box matches the one returned from 
> controller; then sets the value of select box to that value). 
>
> function selbx(elementID, value_returned_from_dataset){ 
> for (i=0;i  { 
> if (value_returned_from_dataset == 
> document.getElementById(elementID).options(i).text) 
>   
> {document.getElementById(elementID).options(i).selected = true; 
>
>  }}} 
>
> In controller--- 
> return "selbx('id_of_element','%s');" % dict_obj['freq'] 
>
> dict_obj['freq'] is non-blank. 
> It is a string itself. 
>  
> If individual code-lines are returned, it works. 
>  
>
> Any guess why so? 
>
> Regards, 
> Vineet 
>
> On Nov 8, 6:44 pm, Anthony  wrote: 
> > On Tuesday, November 8, 2011 8:17:41 AM UTC-5, Vineet wrote: 
> > 
> > > > If 'myvar' is a Python variable, you're going 
> > 
> > > 'myvar' is a not a python variable. 
> > > I pass the id of html element as argument. 
> > > Javascript code sets the value of that html element. 
> > 
> > OK, but same problem -- 'myvar1' isn't a javascript variable either -- 
> it 
> > is a string identifying an html element. So you would still have to 
> return 
> > 'abc("myvar1")', or maybe 'abc("#myvar1")', depending on how you are 
> using 
> > it in the code. 
> > 
> > Anthony



[web2py] Re: ajax function with eval : return js function from controller

2011-11-08 Thread Vineet
I checked the js returned from controller function.
It is
selbx('edit_freq','daily');

selbx function is there in the View.

-- Vineet

On Nov 8, 7:04 pm, Vineet  wrote:
> Something is wrong in the function.
> I defined a test js function in View.
>
> function alrt(mesg) {
> alert(mesg) };
>
> And in Controller,
> return "alrt('Hello World!');"
>
> It works.
>
> The actual js function is---
> (it sees which value of select box matches the one returned from
> controller; then sets the value of select box to that value).
>
> function selbx(elementID, value_returned_from_dataset){
>             for (i=0;i              {
>                 if (value_returned_from_dataset ==
> document.getElementById(elementID).options(i).text)
>
> {document.getElementById(elementID).options(i).selected = true;
>
>                      }}}
>
> In controller---
> return "selbx('id_of_element','%s');" % dict_obj['freq']
>
> dict_obj['freq'] is non-blank.
> It is a string itself.
> 
> If individual code-lines are returned, it works.
> 
>
> Any guess why so?
>
> Regards,
> Vineet
>
> On Nov 8, 6:44 pm, Anthony  wrote:
>
>
>
> > On Tuesday, November 8, 2011 8:17:41 AM UTC-5, Vineet wrote:
>
> > > > If 'myvar' is a Python variable, you're going
>
> > > 'myvar' is a not a python variable.
> > > I pass the id of html element as argument.
> > > Javascript code sets the value of that html element.
>
> > OK, but same problem -- 'myvar1' isn't a javascript variable either -- it
> > is a string identifying an html element. So you would still have to return
> > 'abc("myvar1")', or maybe 'abc("#myvar1")', depending on how you are using
> > it in the code.
>
> > Anthony- Hide quoted text -
>
> - Show quoted text -


[web2py] Re: ajax function with eval : return js function from controller

2011-11-08 Thread Vineet
Something is wrong in the function.
I defined a test js function in View.

function alrt(mesg) {
alert(mesg) };

And in Controller,
return "alrt('Hello World!');"

It works.

The actual js function is---
(it sees which value of select box matches the one returned from
controller; then sets the value of select box to that value).

function selbx(elementID, value_returned_from_dataset){
for (i=0;i wrote:
> On Tuesday, November 8, 2011 8:17:41 AM UTC-5, Vineet wrote:
>
> > > If 'myvar' is a Python variable, you're going
>
> > 'myvar' is a not a python variable.
> > I pass the id of html element as argument.
> > Javascript code sets the value of that html element.
>
> OK, but same problem -- 'myvar1' isn't a javascript variable either -- it
> is a string identifying an html element. So you would still have to return
> 'abc("myvar1")', or maybe 'abc("#myvar1")', depending on how you are using
> it in the code.
>
> Anthony


[web2py] Re: ajax function with eval : return js function from controller

2011-11-08 Thread Anthony
On Tuesday, November 8, 2011 8:17:41 AM UTC-5, Vineet wrote:
>
> > If 'myvar' is a Python variable, you're going 
>
> 'myvar' is a not a python variable. 
> I pass the id of html element as argument. 
> Javascript code sets the value of that html element.


OK, but same problem -- 'myvar1' isn't a javascript variable either -- it 
is a string identifying an html element. So you would still have to return 
'abc("myvar1")', or maybe 'abc("#myvar1")', depending on how you are using 
it in the code.

Anthony


[web2py] Re: ajax function with eval : return js function from controller

2011-11-08 Thread Vineet
> Probably a typo, but missing the closing single quote (') after the }} for
> the URL.

It is a typo here. It is correct in actual code.

> If 'myvar' is a Python variable, you're going

'myvar' is a not a python variable.
I pass the id of html element as argument.
Javascript code sets the value of that html element.

>From your reply, I guess that it is OK to return a javascript function
from controller (the way I did), provided that I adhere to your hints.

Perhaps then, why my code is failing to evaluate js function in View?

Regards,
Vineet


On Nov 8, 6:05 pm, Anthony  wrote:
> On Tuesday, November 8, 2011 7:45:59 AM UTC-5, Vineet wrote:
>
> > In a View, there is -->   ajax('{{=URL("salhead_edit")}}, [],
> > ':eval');
>
> Probably a typo, but missing the closing single quote (') after the }} for
> the URL.
>
> > "salhead_edit" returns js function -->  'abc(myvar1)'
>
> Unless 'myvar1' is a variable already defined in javascript somewhere in
> your page, that won't work. If 'myvar' is a Python variable, you're going
> to have to insert its actual value (in quotes if it is a string) into the
> JS code. Remember, from web2py's perspective in the controller, the JS code
> you're building is simply a string -- it doesn't know it is code. Something
> like:
>
> myvar1 = 'whatever'
> js = 'abc("%s");' % myvar1
>
> will return:
>
> abc("whatever");
>
> Note, it's a good idea to add the ";" at the end of the line.
>
> Anthony


[web2py] Re: ajax function with eval : return js function from controller

2011-11-08 Thread Anthony
On Tuesday, November 8, 2011 7:45:59 AM UTC-5, Vineet wrote:
>
> In a View, there is -->   ajax('{{=URL("salhead_edit")}}, [], 
> ':eval');
>

Probably a typo, but missing the closing single quote (') after the }} for 
the URL.
 

> "salhead_edit" returns js function -->  'abc(myvar1)'
>

Unless 'myvar1' is a variable already defined in javascript somewhere in 
your page, that won't work. If 'myvar' is a Python variable, you're going 
to have to insert its actual value (in quotes if it is a string) into the 
JS code. Remember, from web2py's perspective in the controller, the JS code 
you're building is simply a string -- it doesn't know it is code. Something 
like:

myvar1 = 'whatever'
js = 'abc("%s");' % myvar1

will return:

abc("whatever");

Note, it's a good idea to add the ";" at the end of the line.

Anthony


[web2py] Re: ajax function : None returned

2011-10-06 Thread Vineet
Hi juanduke !
Thanks for the tip.
It worked.
I will do some more complicated work on this now.

Cheers,
Vineet

On Oct 6, 5:03 pm, juanduke  wrote:
> Hi Vineet:
>
> You need to change this line;
>
>    
>
> for this line:
>
>    
>
> (change id='name' for name="name")
> HTH!!!
> Bye


[web2py] Re: ajax function : None returned

2011-10-06 Thread juanduke
Hi Vineet:

You need to change this line;

   

for this line:

   

(change id='name' for name="name")
HTH!!!
Bye



Re: [web2py] Re: ajax function returns None

2011-08-16 Thread Martin Weissenboeck
Sorry, my mistake...
It works!

There has been a file "one.html" and another file "one.html.bak"
The editor opens "one.html.bak" (why?), but web2py uses "one.html" (of
course!)

Thnak you very much!

2011/8/16 Martin Weissenboeck 

> Now I have tried:
>
> {{extend 'layout.html'}}
> 
> 
> 
> 
>
>
> Sorry, same result:  "None"
> echo is called, but request.vars does not contain any value.
> Martin
>
> 2011/8/16 Massimo Di Pierro 
>
> Try
>>
>> 
>>
>> I think this is typo in the book.
>>
>> On Aug 16, 6:53 am, Martin Weissenboeck  wrote:
>> > Hi,
>> >
>> > I have tried the example from chapter 10.3 The ajax Function
>> >
>> > Controller:
>> > def one():
>> > return dict()
>> >
>> > def echo():
>> > return request.vars.name
>> >
>> > one.html:
>> > {{extend 'layout.html'}}
>> > 
>> > 
>> > 
>> > 
>> >
>> > No success, because the value of request.vars.name is None
>> > Just for fun I have tried "request.now", "request.extension",
>> > "request.folder" and so on instead of "request.vars.name" - these
>> examples
>> > worked fine, but I had no chance to get the value of name.
>> >
>> > Version: web2py 1.98.2, started from source with Windows Python 2.7.2
>> > and web2py 1.98.2 Python 2.5
>> >
>> > What is wrong - any ideas?
>> >
>> > Regards, Martin
>>
>
>
>


Re: [web2py] Re: ajax function returns None

2011-08-16 Thread Martin Weissenboeck
Now I have tried:

{{extend 'layout.html'}}






Sorry, same result:  "None"
echo is called, but request.vars does not contain any value.
Martin

2011/8/16 Massimo Di Pierro 

Try
>
> 
>
> I think this is typo in the book.
>
> On Aug 16, 6:53 am, Martin Weissenboeck  wrote:
> > Hi,
> >
> > I have tried the example from chapter 10.3 The ajax Function
> >
> > Controller:
> > def one():
> > return dict()
> >
> > def echo():
> > return request.vars.name
> >
> > one.html:
> > {{extend 'layout.html'}}
> > 
> > 
> > 
> > 
> >
> > No success, because the value of request.vars.name is None
> > Just for fun I have tried "request.now", "request.extension",
> > "request.folder" and so on instead of "request.vars.name" - these
> examples
> > worked fine, but I had no chance to get the value of name.
> >
> > Version: web2py 1.98.2, started from source with Windows Python 2.7.2
> > and web2py 1.98.2 Python 2.5
> >
> > What is wrong - any ideas?
> >
> > Regards, Martin
>


[web2py] Re: ajax function returns None

2011-08-16 Thread Massimo Di Pierro
Try



I think this is typo in the book.

On Aug 16, 6:53 am, Martin Weissenboeck  wrote:
> Hi,
>
> I have tried the example from chapter 10.3 The ajax Function
>
> Controller:
> def one():
>     return dict()
>
> def echo():
>     return request.vars.name
>
> one.html:
> {{extend 'layout.html'}}
> 
> 
> 
> 
>
> No success, because the value of request.vars.name is None
> Just for fun I have tried "request.now", "request.extension",
> "request.folder" and so on instead of "request.vars.name" - these examples
> worked fine, but I had no chance to get the value of name.
>
> Version: web2py 1.98.2, started from source with Windows Python 2.7.2
> and web2py 1.98.2 Python 2.5
>
> What is wrong - any ideas?
>
> Regards, Martin


Re: [web2py] Re: ajax function submit on script

2011-04-28 Thread Stifan Kristi
thank you so much for your correction, massimo. it runs right now with:
jQuery(document).ready(function(){
jQuery('.view').click(function(){jQuery('.comments').slideToggle()});
jQuery('.post').click(function(){jQuery('.form').slideToggle()});
jQuery('.post').submit(function(){ajax('{{=request.controller}}', [],
'comments hidden')});
});

it seems for the first, second and third data inserted the ajax function is
not running properly, i mean, i must refresh the browser, but after the
third data, ajax function is running smoothly, where is my wrong code that i
must fix it?

currently i separate the javascript into the static js folder like code
above, and call it on the views.

thank you very much before

On Thu, Apr 28, 2011 at 9:12 PM, Massimo Di Pierro <
massimo.dipie...@gmail.com> wrote:

> yes but the syntax is incorrect:
>
> ajax('blog_show', 'comments hidden')
>
> should be
>
> ajax('blog_show', [], 'target_id')
>
>
>
> On Apr 28, 8:58 am, 黄祥  wrote:
> > hi,
> >
> > is it possible to put ajax function submit on script?
> > e.g.
> > 
> > jQuery(document).ready(function(){
> > jQuery('.view').click(function()
> > {jQuery('.comments').slideToggle()});
> > jQuery('.post').click(function(){jQuery('.form').slideToggle()});
> > jQuery('.post').submit(function(){ajax('blog_show', 'comments
> > hidden')});});
> >
> > 
> >
> > i've already tried it, no error occured but the ajax function didn't
> > work. my intention is when a user submit a comment form (using crud on
> > controller) it will show without reloading the page, or is there any
> > others way to do this?
> >
> > please give an advice and please correct me if my code is wrong.
> >
> > many thanks before


[web2py] Re: ajax function submit on script

2011-04-28 Thread Massimo Di Pierro
yes but the syntax is incorrect:

ajax('blog_show', 'comments hidden')

should be

ajax('blog_show', [], 'target_id')



On Apr 28, 8:58 am, 黄祥  wrote:
> hi,
>
> is it possible to put ajax function submit on script?
> e.g.
> 
> jQuery(document).ready(function(){
>     jQuery('.view').click(function()
> {jQuery('.comments').slideToggle()});
>     jQuery('.post').click(function(){jQuery('.form').slideToggle()});
>     jQuery('.post').submit(function(){ajax('blog_show', 'comments
> hidden')});});
>
> 
>
> i've already tried it, no error occured but the ajax function didn't
> work. my intention is when a user submit a comment form (using crud on
> controller) it will show without reloading the page, or is there any
> others way to do this?
>
> please give an advice and please correct me if my code is wrong.
>
> many thanks before


[web2py] Re: ajax function

2011-04-06 Thread DenesL

You can add the constant as an arg but to the url.
Also note that components, i.e. LOAD(), allow args and vars.


On Apr 6, 8:59 am, leone  wrote:
> I need to use ajax web2py function passing a costant, es.:
>
>       ajax(url,[ 'namefld1', 'namefld2', 'costant-value'], ':eval')
>
> Exploring code I see that I must insert an input tag with desidered
> value and call it by name.
> There is a smarter way?
> Thanks
>
> On 5 Apr, 16:06, Ross Peoples  wrote:
>
>
>
>
>
>
>
> > Could you be a little more specific? Are you trying to pass args and vars?
> > Or are you trying to load HTML using AJAX and sending it to a target DIV? If
> > you are using web2py's ajax function, you may be limited to what you can do.
> > Worst case, you can always try calling jQuery's load() method:
>
> > var url = {{=URL('ajax_view.load', args={'arg1': 'my', 'arg2', 'value'})}};
> > jQuery('#target').load(url);
>
> > Or like this:
>
> > var url = {{=URL('ajax_view.load')}};
> > jQuery('#target').load(url, {arg1: 'my', arg2, 'value'});
>
> > Does this help?


[web2py] Re: ajax function

2011-04-06 Thread Massimo Di Pierro
Make an 'hidden' input field.

On Apr 6, 7:59 am, leone  wrote:
> I need to use ajax web2py function passing a costant, es.:
>
>       ajax(url,[ 'namefld1', 'namefld2', 'costant-value'], ':eval')
>
> Exploring code I see that I must insert an input tag with desidered
> value and call it by name.
> There is a smarter way?
> Thanks
>
> On 5 Apr, 16:06, Ross Peoples  wrote:
>
>
>
>
>
>
>
> > Could you be a little more specific? Are you trying to pass args and vars?
> > Or are you trying to load HTML using AJAX and sending it to a target DIV? If
> > you are using web2py's ajax function, you may be limited to what you can do.
> > Worst case, you can always try calling jQuery's load() method:
>
> > var url = {{=URL('ajax_view.load', args={'arg1': 'my', 'arg2', 'value'})}};
> > jQuery('#target').load(url);
>
> > Or like this:
>
> > var url = {{=URL('ajax_view.load')}};
> > jQuery('#target').load(url, {arg1: 'my', arg2, 'value'});
>
> > Does this help?


[web2py] Re: ajax function

2011-04-06 Thread leone
I need to use ajax web2py function passing a costant, es.:

  ajax(url,[ 'namefld1', 'namefld2', 'costant-value'], ':eval')

Exploring code I see that I must insert an input tag with desidered
value and call it by name.
There is a smarter way?
Thanks





On 5 Apr, 16:06, Ross Peoples  wrote:
> Could you be a little more specific? Are you trying to pass args and vars?
> Or are you trying to load HTML using AJAX and sending it to a target DIV? If
> you are using web2py's ajax function, you may be limited to what you can do.
> Worst case, you can always try calling jQuery's load() method:
>
> var url = {{=URL('ajax_view.load', args={'arg1': 'my', 'arg2', 'value'})}};
> jQuery('#target').load(url);
>
> Or like this:
>
> var url = {{=URL('ajax_view.load')}};
> jQuery('#target').load(url, {arg1: 'my', arg2, 'value'});
>
> Does this help?


[web2py] Re: ajax function

2011-04-05 Thread Ross Peoples
Could you be a little more specific? Are you trying to pass args and vars? 
Or are you trying to load HTML using AJAX and sending it to a target DIV? If 
you are using web2py's ajax function, you may be limited to what you can do. 
Worst case, you can always try calling jQuery's load() method:

var url = {{=URL('ajax_view.load', args={'arg1': 'my', 'arg2', 'value'})}};
jQuery('#target').load(url);

Or like this:

var url = {{=URL('ajax_view.load')}};
jQuery('#target').load(url, {arg1: 'my', arg2, 'value'});

Does this help?


[web2py] Re: ajax function target id null

2010-06-24 Thread mdipierro
You cannot but if you do

ajax('func1', ['id1'], ':eval')

it will interpret the returned page as json and evaluate it. id If you
return 'null' or '', it should work as expected and not raise any
error.

On Jun 24, 9:47 am, ilovesss2004  wrote:
> Hi,
> I use the ajax function as follows:
>
> ajax('func1', ['id1'], '')
>
> because I don't need to send some value to the html page, so I set the
> third parameter null. But IE raises error
> 'document.getElementById(...)' is null or not an object.
>
> How can I use the ajax function when I don't want to send values to
> html page?