Hi,
I am trying to use JavaScript Query Builder plugin (querybuilder.js.org) with web2py. The plugin is installed successfully and I can see the querybuilder object in my view. I want to finally pass the string containing the filters selected from the view to another controller function for further processing. The code I am using on the view is below:
<button onclick='myFunction();'>Get rules</button>
<script>
function myFunction();{
var result = JSON.stringify($('#builder-basic').queryBuilder('getRules'), null, 2);
ajax('{{=URL('default', 'showfilters', vars=dict(result=result))}}', [], ':eval');
}
</script>
I want to pass ‘result’ variable to ‘showfilters’ controller function and call ‘showfilters’ view on clicking on ‘Get rules’ button. But the above code doesn’t work and gives this error:
<type 'exceptions.NameError'> name 'result' is not defined
I understand this could be because 'result' variable is not defined in my controller function corresponding to this view. What is the correct way to pass the value of a variable declared through Java Script to a controller function in web2py?
Please help me here – I am novice to both web2py and Java Script and have been struggling with this for quite some time. I would prefer to pass the variable result through dictionary and not as an argument, as it will contain spaces and special characters which I want to preserve in the string.
Thanks,
Madhavi
ajax('{{=URL('default', 'showfilters')}}' + '?result=' + result, [], ':eval');
ajax('{{=URL('default', 'showfilters')}}' + '?result1=' + result1 + '&result2='+result2, [], ':eval');
ajax('{{=URL('default', 'showfilters')}}/' + result1 + '/' + result2, [], ':eval');
ajax('{{=URL('default','save_user')}}/'+agent_id+'?first_name='+encodeURIComponent($('#first_name').val())+'&last_name='+encodeURIComponent($('#last_name').val())+'&email='+encodeURIComponent($('#email').val())+'&phone='+encodeURIComponent($('#phone').val()),[],':eval');