librelist archives

« back to archive

Trying to get AJAX to update a span updating mongo record, but it's opening a new page.

Trying to get AJAX to update a span updating mongo record, but it's opening a new page.

From:
Andrew Gordon
Date:
2012-07-24 @ 03:56
Hi all,

I am not understanding something about AJAX and Flask.

I have a project wherein I display mongodb records in the browser, which 
has been working fine.

I added functionality for users to increment votes on a record; to Vote 
it up if they like it. But I originally I was then refreshing the entire 
page with the new vote, using a redirect, which is clumsy. So I am 
trying to get AJAX to send the data over to the mongodb record and then 
update the span where I want the votes to appear without having to 
reload the entire page.

Problem is, the setup I have going, while still updating the record, is 
now loading a new page with the HTML i want returned only to the span 
where the vote tally should be (that is, it's loading a new page with 
only the word "test" in it (the test value I am currently returning)).

The jQuery (the library I am using) is loading fine and there are no 
other problems (as far as I can tell).

I have the relevant HTML and JS here: https://pastee.org/f2r3f
and the python is here: https://pastee.org/guju9

I am also having trouble figuring out how to return the individual vote 
value for the specified mongodb record back to the browser, even with 
jsonify (which returns {"votes":'_id'}, but that's another issue. 
Hopefully someone can help me understand how to make AJAX work for me 
with Flask in this regard.

Thanks in advance,
drew


<https://pastee.org/guju9>

Re: [flask] Trying to get AJAX to update a span updating mongo record, but it's opening a new page.

From:
pronoyc@gmail.com
Date:
2012-07-24 @ 04:50
I think it's the fifth time I am probably saying the same thing :)

Use Flask-Sijax. You don't need to worry about most of the annoying things
that come with Ajax with that.


 Hi all,
>
> I am not understanding something about AJAX and Flask.
>
> I have a project wherein I display mongodb records in the browser, which
> has been working fine.
>
> I added functionality for users to increment votes on a record; to Vote it
> up if they like it. But I originally I was then refreshing the entire page
> with the new vote, using a redirect, which is clumsy. So I am trying to get
> AJAX to send the data over to the mongodb record and then update the span
> where I want the votes to appear without having to reload the entire page.
>
> Problem is, the setup I have going, while still updating the record, is
> now loading a new page with the HTML i want returned only to the span where
> the vote tally should be (that is, it's loading a new page with only the
> word "test" in it (the test value I am currently returning)).
>
> The jQuery (the library I am using) is loading fine and there are no other
> problems (as far as I can tell).
>
> I have the relevant HTML and JS here: https://pastee.org/f2r3f
> and the python is here: https://pastee.org/guju9
>
> I am also having trouble figuring out how to return the individual vote
> value for the specified mongodb record back to the browser, even with
> jsonify (which returns {"votes":'_id'}, but that's another issue. Hopefully
> someone can help me understand how to make AJAX work for me with Flask in
> this regard.
>
> Thanks in advance,
> drew
>
>
>  <https://pastee.org/guju9>
>



-- 
Regards,

Pronoy Chopra
http://blog.pronoy.in <http://www.pronoy.in/about>/
http://www.twitter.com/pronoyc

Re: [flask] Trying to get AJAX to update a span updating mongo record, but it's opening a new page.

From:
Andrew Gordon
Date:
2012-07-24 @ 15:34
Thanks, I've seen the suggestion and might give it a whirl later on. But 
I am also taking this opportunity to learning more about the general 
ins-and-outs of AJAX in something like jQuery.

thanks for the suggestion.

On 7/23/12 11:50 PM, pronoyc@gmail.com wrote:
> I think it's the fifth time I am probably saying the same thing :)
>
> Use Flask-Sijax. You don't need to worry about most of the annoying
> things that come with Ajax with that.
>
>
>     Hi all,
>
>     I am not understanding something about AJAX and Flask.
>
>     I have a project wherein I display mongodb records in the browser,
>     which has been working fine.
>
>     I added functionality for users to increment votes on a record; to
>     Vote it up if they like it. But I originally I was then refreshing
>     the entire page with the new vote, using a redirect, which is
>     clumsy. So I am trying to get AJAX to send the data over to the
>     mongodb record and then update the span where I want the votes to
>     appear without having to reload the entire page.
>
>     Problem is, the setup I have going, while still updating the record,
>     is now loading a new page with the HTML i want returned only to the
>     span where the vote tally should be (that is, it's loading a new
>     page with only the word "test" in it (the test value I am currently
>     returning)).
>
>     The jQuery (the library I am using) is loading fine and there are no
>     other problems (as far as I can tell).
>
>     I have the relevant HTML and JS here: https://pastee.org/f2r3f
>     and the python is here: https://pastee.org/guju9
>
>     I am also having trouble figuring out how to return the individual
>     vote value for the specified mongodb record back to the browser,
>     even with jsonify (which returns {"votes":'_id'}, but that's another
>     issue. Hopefully someone can help me understand how to make AJAX
>     work for me with Flask in this regard.
>
>     Thanks in advance,
>     drew
>
>
>     <https://pastee.org/guju9>
>
>
>
>
> --
> Regards,
>
> Pronoy Chopra
> http://blog.pronoy.in <http://www.pronoy.in/about>/
> http://www.twitter.com/pronoyc
>