On Jun 20, 8:58 pm, Yarko Tymciurak <[email protected]>
wrote:
> Well, maybe this is a good exercise / tutorial in debugging:
>
> On Jun 20, 9:02 am, mdipierro <[email protected]> wrote:
>
> # this just displays view/default/index.html as it is> def index():
> > return dict()
>
> # demo: get input from the client and do something with it
> # - split, so you can put a breakpoint, and see separately what was
> sent, what is returned> def process():
> > # return request.vars.test.upper()
>
> x = request.vars.test # note: this is rigid: couples
> process() to the id-tag: test
> return x.upper() # just uppercase the input
>
>
>
> > #index.html
> > {{extend 'layout.html'}}
>
> <!- A js debugger will show that there is an error: a missing id
> 'test';
> let's just add that to this input field;
>
> NOTE: this example has confused two important things:
>
> - if you had an input, and submitted, it's value would have been
> labeled by the 'name' tag - just to clarify that is true, let's rename
> it also
>
> - since id is what is being tagged, we'll also add a non-input id
> so you can see the full effect of this
> -->
> <input id='test' name='test_name'>
>
> <!- this id is where the result of your controller 'process()' will
> be placed;
> if you had anything in the div, it would be replaced
> -->
>
> > <div id="target"><div>
>
> <!- To see the next bug, you have to inspect the element "click me"
> in your browser;
>
> You will see that the call is formed as "ajax( '/my_app/
> process', ['test'], 'target')"
>
> First guess would make you think that you need to add the
> 'default' controller, but this is wrong too....
>
> It may not be clear - this is the ajax call defined in views/
> web2py_ajax.hml
>
> This in turn uses jQuery.ajax() --- and we won't get into
> debugging that here, but in general note that you could insert a
> breakpoint in your js by inserting a js call where
> you want to break: debugger;
>
> For now, note the documentation
> athttp://www.web2py.com/book/default/section/10/3?search=ajax
>
> I'll leave it to you as an exercise to see if adding a <base
> href=...> tag to the head of your document would allow you to use the
> output of URL()... I am not sure.
>
> > <button onclick="ajax('{{=URL(r=request,f='process')}}',
> > ['test'],'target')">click me</button>
>
> -->
>
> <button onclick="ajax('process', ['test'], 'target')">click me</
> button>
>
> Note that you could replace the <input id=....> field just as easily
> with something like:
>
> <span id='test'>All sorts of stuff ....</span>
>
> Hopefully, this has been helpful.
>
> - Yarko
>
Thanks a lot for your detailed reply Yarko :)
Now I have the idea and get my program working.
And I think maybe more reading and learning about ajax will help me to
use web2py better.
By the way I'm also interested in to connect client-side and server-
side(python program) by using pyamf.
Can you give some advise?