开发者

Refreshing datalist and pagenumbers using DJANGO and AJAX

I am trying to reload a "next page" without reloading the whole page again. I just want my datatable to be updated. I found out this is done with ajax. After doing some research on the internet I now know that your ajax/javascript goes to a certain url and in django you make the view mapped to that url return new data. Untill this point everything was clear to me. But now I had to make some sort of javascript to do that and Im completely lost.

This is the datalist in my template

<div class="project-container">
    {% for project in pagination.projects %}
        <div class="project">
            <h4 class="strong">{{ project.name }}</h4>
            <div class="project-details-vars">
                <p>{{ project.info_veld_1 }}</p>
                <p>{{ project.info_veld_2 }}</p>
                <p>{{ project.info_veld_3 }}</p>
                <p>{{ project.info_veld_4 }}</p>
                <p>{{ project.info_veld_5 }}</p>
            </div>
        </div>
    {% endfor %}
</div>

This is my custom paginator in my template.

<div id="paginator">
    {% if pagination.prevPage %}
    <a href="/page/{{ pagination.prevPage }}">
        <img src="/static/images/arrow-left.png" />
    </a>
   开发者_如何学Python {% endif %}
    {% if pagination.nextPage %}
        <a href="/page/{{ pagination.nextPage }}">
            <img src="/static/images/arrow-right.png" />
        </a>
    {% endif %}
</div>

Can some1 please show me a javascript that triggers on the url and that only refreshes the data on the data list AND updates the url.

Thanks in advance :)


There is a nice javascript called ajaxroutine. See this link. All you need to do is download the script, use

<script src="text/javascript" src="ajaxroutine.js"></script>

Then you call

ajaxpack.getAjaxRequest("/Example", "name=George&age=27", processGetPost, "txt")

in your html code, where "/Example" is your URL, "name=George&age=27" are additional parameters, processGetPost is a callback, a javascript function which will run after in your code after the response and "txt" is just to know, that the response is in txt format (I think it can also be in xml, but honestly I never tried it). This ajaxroutine works for me fine. You should try it. There's much more explanation in the link I mentioned at the begining.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜