-1

I have a server running with Django. In a template I have an form with submit action wich send infromation to a views.py from an app.

So, when a user click on a button, he submit the information to Django, and to prevent the page to refresh, I've made a function that submits but doesn't refresh the page to keep some data on the page. This is the js function:

   $(function() {
      $('#Values_all_Form').submit(function(e){
        $.post('/en/projects/ford/submit', $(this).serialize(), function(e){ 
        });
        e.preventDefault();
      });
    });

How can I make in ajax or javascript an function, after submit to refresh or reload a Div where I have an table like this:

<div id="divResult">
    <table>
        <tr>
            <td>author</td>
            <td>qty</td>
            <td>Amount</td>
        </tr>

        {% for author, values in data.items %}
        <tr>
            <td>{{author}}</td>
            {% for v in values.0 %}
            <td>{{v}}</td>
            {% endfor %}
        </tr>
        {% endfor %}
    </table>
</div>
J.C Julien
  • 153
  • 2
  • 10
  • http://stackoverflow.com/questions/19454310/stop-form-refreshing-page-on-submit – Hearner Aug 07 '15 at 08:14
  • Thanks, but I've made that in my js function to prevent the refres the hole page , what I want is refresh just a div where it is my table – J.C Julien Aug 07 '15 at 08:21
  • Use the event `onsubmit` in your form and use `document.getElementById('myiframe').reload(true);` or `location.reload():` – Hearner Aug 07 '15 at 08:24
  • The form and the div are two separate things. `
    ... some code ....
    {% for author, values in data.items %} {% for v in values.0 %} {% endfor %} {% endfor %}
    author qty Amount
    {{author}}{{v}}
    ` I want to refresh/reload just the div not the form.
    – J.C Julien Aug 07 '15 at 08:43

1 Answers1

0

Just did something like this yesterday. I used setTimeout to allow the database time to populate before refreshing the div. I inserted it into my submit function. If you are trying to refresh the html inside your {% for %} loop, you would have to wrap the loop in some sort of wrapper div and target that.

setTimeout (function() {
  $('#divResult').load(document.URL + ' #divResult');
}, 1000);
B.S.
  • 16
  • 1
  • Thanks, but i figured out how to make. Is something related like your function but I don't need a timeout, because that content is refreshed one time. `$(function(){ $('#Values_all').submit(function(e){ $.post('/en/projects/ford/submit', $(this).serialize(), function(e){ $('#divResul').load('/en/data_table/' + '#divResul'); }); e.preventDefault(); }); });` – J.C Julien Aug 11 '15 at 06:31