On Jul 8, 3:02 pm, Ross Peoples <[email protected]> wrote:
> You're doing it right, but there are a couple of things to keep in mind.
> Using $.post(url, {input_n: input_number}); is easier than using $.ajax, but
> that's merely preference. The other thing you should know is that if a
> web2py ticket is generated during an AJAX call, you will not know about it.
> The call will appear to do nothing, which sounds like what you described.
>
> Whenever I make an AJAX call, this is how I usually do it:
>
> jQuery.post(url, {myvar: myvalue}, function(data) {
> // do something with the returned data from server (only gets called if
> call was successful).}).error(function(data) {
>
> // error is usually HTML, so convert it to plain text for the alert()
> function.
> alert(data.replace(/(<.*?>)/ig,""));
>
> });
>
> This way, you will know if AJAX was successful or failed.
Hello!
I would like to save the JavaScript variable to a web2py session
variable.
I have tried the following in my view (that has no controller
associated with it):
function submit_form(input_number, input_egn) {
$('input#user_input_number').val(input_number);
$('input#user_input_egn').val(input_egn);
$.ajax({
type: "POST",
url: "http://127.0.0.1:8000/games/xs-software/vaucher.html",
data: "{game_id : $
('input#user_input_number').val(input_number)}"
success: function(msg){
alert( "Data Saved: " + msg );
}
});
{{session.game_id = 4}}
{{if request.vars['game_id']:
session.game_id = request.vars['game_id']}}
$('form:first').submit();
return false;
}
, but i receice the following error traceback:
1 Traceback (most recent call last):
2 File "/home/vpetkov/Documents/cashterminal_new/terminal/gluon/
rocket.py", line 1064, in run
3 self.run_app(conn)
4 File "/home/vpetkov/Documents/cashterminal_new/terminal/gluon/
rocket.py", line 1531, in run_app
5 self.environ = environ = self.build_environ(sock_file, conn)
6 File "/home/vpetkov/Documents/cashterminal_new/terminal/gluon/
rocket.py", line 1363, in build_environ
7 request = self.read_request_line(sock_file)
8 File "/home/vpetkov/Documents/cashterminal_new/terminal/gluon/
rocket.py", line 1138, in read_request_line
9 raise SocketTimeout("Socket timed out before request.")
10 SocketTimeout: Socket timed out before request.
I mean, does web2py has a way to RECEIVE JavaScript variables FROM
Python/web2py templates? Where are they stored? And how to call these
JavaScript variables inside {{ }} in a web2py view/template?
Thank you in advance for your answers!