The following seems to work:
This in the view:
var up = function () {
this.attr({opacity: 1.0});
var locx_val = this.attr("x");
$.ajax({
type: "POST",
url: "{{ =URL('new_post') }}",
data: {locx:locx_val}
})
results in the db:
<Storage {'locx': '348'}>
Which is the x coordinate of the Raphael element at the end (up) of the
drag.
The data is indeed added to the url!
Thank you Massimo.
On Wednesday, October 3, 2012 8:29:26 PM UTC+2, Richard wrote:
>
> That works better indeed, but,
>
> var up = function () {
> this.attr({opacity: 1.0});
> var locx = this.attr("x");
> $.ajax({
> type: "POST",
> url: "{{=URL('new_post')}}",
> data: locx})
>
> gives a record insert with
>
> Controller :
> def new_post():
> db.post.insert(your_message=request.vars.locx)
>
> Must the variable be included in the ajax url call? I read this in
> https://groups.google.com/forum/#!msg/web2py/jlB5SMdy1R0/1WbFijWEy_sJ
>
>
>
> On Wednesday, October 3, 2012 7:32:31 PM UTC+2, Massimo Di Pierro wrote:
>>
>> url: "{{URL('new_post')}}",
>>
>> should be
>>
>> url: "{{=URL('new_post')}}",
>>
>> On Wednesday, 3 October 2012 11:14:03 UTC-5, Richard wrote:
>>>
>>> Massimo,
>>>
>>> I thought so.
>>>
>>> But what is missing in th follwowing?
>>>
>>> View:
>>> var up = function () {
>>> this.attr({opacity: 1.0});
>>> var locx = this.attr("x");
>>> $.ajax({
>>> type: "POST",
>>> url: "{{URL('new_post')}}",
>>> data: locx})
>>> };
>>>
>>> Controller :
>>> def new_post():
>>> db.post.insert(your_message=request.vars.locx)
>>>
>>>
>>> On Wednesday, October 3, 2012 5:50:44 PM UTC+2, Massimo Di Pierro wrote:
>>>>
>>>> ajax helper is a just a shortcut for $.ajax but I recommend using
>>>> $.ajax. It is more flexible.
>>>>
>>>> On Wednesday, 3 October 2012 09:37:09 UTC-5, Richard wrote:
>>>>>
>>>>> Hi,
>>>>>
>>>>> I am using Raphael for drawing diagrams and want to store de location
>>>>> of the elements in the database.
>>>>>
>>>>> Do I need $.ajax or can I stick to ajax helper?
>>>>>
>>>>> View:
>>>>> var up = function () {
>>>>> this.attr({opacity: 1.0});
>>>>> var locx = this.attr("x");
>>>>> ajax('new_post', ['locx'], 'resp');
>>>>> };
>>>>>
>>>>> Controller :
>>>>> def new_post():
>>>>> db.post.insert(your_message=request.vars.locx)
>>>>>
>>>>> Any hint would be welcome
>>>>> Richard
>>>>>
>>>>
--