My question is ---
If I have two javascript variables, which are to be passed to a
controller through URL helper as under --
[CODE]
<script>
....
var param1 = 'value1' ;
var param2 = 'value2'
.... "{{URL(r=request,c='static',f='action')}}/"+param1¶m2
that did not work
.... "{{URL(r=request,c='static',f='action')}}/"+(param1,param2)
didn't work either.
.....
</script>
[/CODE]
How do I code it?
Thanks,
Vineet
<script>
....
var param1 = 'value1' ;
var param2 = 'value2'.... "{{URL(r=request,c='static',f='action')}}/"+param1¶m2
On Dec 4, 12:10 am, Vineet <vineet.deod...@gmail.com> wrote:
> I referred to the below-mentioned thread (but could not reply to it).
>
> https://groups.google.com/group/web2py/browse_thread/thread/61d57e887...
You can try: {{URL('static','action',args=[param1,param2])}}
{{=URL(...)}} + '/' + 'p1=' + param1 + '/' + 'p2=' + param2
@Brian, I would be interested & grateful to you if you can send me a
copy of jQuery.query
(as mentioned by you). Thanks
---Vineet
On Dec 4, 3:53 am, Brian M <bmere...@gmail.com> wrote:
> I've used a jQuery plugin called jQuery.query that can manipulate URLs. If
> memory serves correct you do something along the lines of
> $.query.set('var', value) to set querystring values. And $.query.get('var')
> to retrieve.
>
> Sadly the jQuery team seems to have taken down the jQuery plugins site and
> I can't seem to find any other links to the source. Even the author's site<http://blairmitchelmore.com/jquery>just links back to the jQuery plugins site :\ I might be able to dig up a
> @Anthony, thanks. Your method worked.
> Secondly, if I want to pass arguments by name, would it be okay to do
> something like this---->>
>
> {{=URL(...)}} + '/' + 'p1=' + param1 + '/' + 'p2=' + param2
Almost. You want:
{{=URL(...)}} + '?p1=' + param1 + '&p2=' + param2
...then look for p1 & p2 in request.vars.
{{=URL(...,vars=dict(p1=param1,p2=param2))}}
On Dec 4, 12:33 pm, Massimo Di Pierro <massimo.dipie...@gmail.com>
wrote:
--- Vineet
On Dec 5, 6:16 am, Brian M <bmere...@gmail.com> wrote:
> Vineet,
>
> My copy of jQuery.query.js is attached - I'm assuming since it's released
> under the WTFPL the author won't mind :D
>
> You may also want to look at these:http://stackoverflow.com/questions/2053157/how-to-use-jquery-to-manip...http://stackoverflow.com/questions/4344405/jquery-url-builder-parserhttp://stackoverflow.com/questions/1090948/change-url-parameters-with...
>
> Brian
>
> jquery.query.js
> 7KViewDownload
{{=URL('controller','action', args=[arg1, arg2])}}
I tried this<h3 {{=A(' ..... ',_href=URL('action'))}}/param1/param2 </h3>
and it did not work.:)what is the right way of doing it?
thanks for the immediate reply.param1 and param2 are determined on the client side.
how can it be generated by javascript?
<script>
jQuery(function() {
var param1 = 'hello'
var param2 = 'world'
jQuery('a#mylink').attr('href', '{{=URL("action")}}' + '/' + param1 + '/' + param2);
});
</script>
<h3>{{=A('...', _href='', _id='mylink')}}</h3>
<script>
jQuery(function() {
var param1 = 'hello'
var param2 = 'world'
jQuery('a#mylink').attr('href', '{{=URL("action", args=["' + param1 + '","' + param2 + '"])}}');
});
</script>
<h3>{{=A('...', _href='', _id='mylink')}}</h3>let me brief what i am doing. I am building an application accessing google maps api v3. I need the function that decide if a certain point is within certain bounds. my understanding is that i need to do that in the view ( by passing the point and the coordinates of the bounds ). the view js can access them if they in {{ }}.
is there a solution without using jquery?
def index():
"""
example action using the internationalization operator T and flash
rendered by views/default/index.html or views/generic.html
"""
response.title = "Passing Args to URL through JS"
response.subtitle = T('Home')
form = SQLFORM.factory(
Field('email', 'string', requires=IS_NOT_EMPTY(IS_EMAIL())),
Field('password', 'string', requires=IS_NOT_EMPTY()),
_name='foo_form', _id='foo_form')
return dict(message=T('Demo'), form = form)
def validate():
import gluon.contrib.simplejson as sj
try:
if request.vars.email == 'm...@email.com' and request.vars.password == 'mypassword':
#success
return sj.dumps(dict(success=True, message='Success!'))
else:
#fail
return sj.dumps(dict(error=True, message='Oops wrong login info!'))
except:
#fail
return sj.dumps(dict(error=True, message='Login Failed, Please Try Again!'))
def receiving_page():
response.title = "Passing Args to URL through JS"
response.subtitle = T('Results')
#get passed args
email = request.args[0]
password = request.args[1]
return dict(email = email, password = password)
{{left_sidebar_enabled=right_sidebar_enabled=False}}
{{extend 'layout.html'}}
<h1>{{=message}}</h1>
{{=form}}
<div id="status">Please Login</div>
<script type="text/javascript">
$(function() {
$('#foo_form').bind('submit',function(event){
var email = $('#no_table_email').val();
var password = $('#no_table_password').val();
alert("Submitting "+email+" "+password);
$.post('{{=URL(r=request, f="validate")}}',
$(this).serialize(),
function(json) {
if(json.error) {
//alert(json.message);
$('#status').html(json.message);
} else {
//alert(json.message);
$('#status').html(json.message);
destination ='{{=URL(r=request, f="receiving_page")}}/'+email +'/'+password;
//alert(destination);
parent.window.location = destination;
}
}, 'json');
return false;
});
});
</script>
{{block left_sidebar}}New Left Sidebar Content{{end}}
{{block right_sidebar}}New Right Sidebar Content{{end}}
good day great folks..i've been encountering same problem here..i have 2 variables in my function to pass in my controller...i just cant do it right trying lot of options already..here's my code:$(function() {$('#client-login').bind('submit',function(event){var email = $('#email').val();var password = $('#password').val();$.post('{{ constant('BB_URL_API') }}guest/client/login',$(this).serialize(),function(json) {if(json.error) {alert(json.error.message);} else {parent.window.location ='http://localhost/course_booking/index.php/display/client_info/'+email +password; //this doesnt work...what is the right approach in this,,pls help}}, 'json');return false;});});and how should my controller look...?thanks people