0

everyone. So i've been going through this documentation: http://flask.pocoo.org/docs/patterns/jquery/. I have a Flask site up and running, but, when i try to set up what they have, i just get the error: GET http://127.0.0.1:5000/add_numbers?a=5&b=5 404 (NOT FOUND)

It just appears that the client can't even establish the connection with the server.

The only thing that differs on my side is how i assign values to the vars a and b. I've also made sure to include the script defining what $SCRIPT_ROOT is. Not sure what to do here. I also have jQuery properly loaded.

I was thinking about trying ajax, but i couldnt find a good example of ajax with python. (i'm pretty new to back end development)

$.getJSON($SCRIPT_ROOT + '/add_numbers', {
            a: 5,
            b: 5
        }, function(data) {                                 
            alert(data.result);
        });

basically, the whole point of what im trying to do is to eventually get data from a database into my javascript. I've managed to get data from my database into my HTML, but not into my JS yet. Thats what im trying.

1 Answer 1

1

$.getJSON is AJAX, it's just wrapped up nice and cleanly. Anyway, if you're using the server-side code from the article, then your JavaScript code has the wrong URL: you should be using $SCRIPT_ROOT + '/_add_numbers' with an _ before add_numbers.

Anyway, if you've got all the data in the HTML already, why not have the JavaScript extract the data from the HTML?

Sign up to request clarification or add additional context in comments.

3 Comments

actually i was using the underscore. i must have copied a version from when i tried not using it in both places. When i had the matching underscores, i still got the same error. That's a good idea, icktoofay - to extract it from the html. I would just really like to understand how to use ajax and python properly, as i'd be using it again, im sure.
@jumpReturn: I'm not entirely sure why you're getting that error — the fact that you see a GET ... 404 at all indicates that it's getting sent correctly, but Flask isn't routing it to the right place.
ef. it turns out i was missing the underscore somewhere. sorry. ;( thanks for the help, guys.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.