django: reading from database after form submission -


i have form in django template call javascript function when it's submitted:

<input name="button2" type="submit" class="test" id="button2" value="submit"        onclick="checksubmitstatus();"/> 

after form submission, code in python views, write data in form database. like:

if request.method == 'post':     customer_data = customers(customerid=1, customername=request.post['textfield1'])     customer_data.save()     return httpresponse(status=204) 

and in javascript function have used ajax data server:

<script type="text/javascript">     function checksubmitstatus() {         $.ajax({             url: "customerdata",             type: 'get',             datatype: 'html',             async: false,             success: function(data) {                 x = data;             }         });             alert(x);     } 

when customerdata reads data db:

return httpresponse(customers.objects.get(customerid=1).customername) 

i expect customerdata deliver modified data (the data enter in template form), while returns previous data. when refresh page can see updated data. i'm sure form data written db, script shows shabby data.

this code doesn't make sense. js function called on submit; is, @ point submit button clicked. @ point, data not exist yet, because haven't submitted form; , in case, ajax call going replaced submission action anyway, callback never going invoked.

i don't understand why have mixed form post / ajax get. either submit form via ajax , return updated data in call; or, submit form normally, , return updated data in standard html response submission.


Comments

Popular posts from this blog

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -

javascript - oscilloscope of speaker input stops rendering after a few seconds -