开发者

Django jQuery get sending logged in users data

I am trying to send my logged in users details along with this request, as I am making use of a if else endif statement on the requested page to render some buttons, ie "add a new item"

My jQuery code looks as follows:

$('.wall').click(function(){
    $('#loading').show();
    $.get(this.href, { request.user: request.user }, function(data){
        $("#wall-tabs").html(data);
        $('#loading').hide();
    });
    $(".wall").find("span").removeClass("selected");
    $(this).find("span").addClass("selected");
    return开发者_如何学Python false;
});

This $.get(this.href, { request.user: request.user }, function(data){ seems to break it, however if I remove the data in between the brackets it works, but I am not seeing the buttons...


Seems to me that you need to specify a parameter name in your data map. So, instead of:

$.get(this.href, { request.user: request.user }, function(data){

You would have:

$.get(this.href, { parameter_name : request.user }, function(data){

Where parameter_name is the name of the get variable the page you are requesting expects to receive.

Take a look at the jQuery docs, about midway down the page:

http://api.jquery.com/jQuery.get/


There is a problem with the syntax used to pick up the variables. You'll need two curly brackets to pick up the variable in the template. Something like this: {{ request.user }}.

However I am not sure that you can include it directly as there is an obvious clash with the JS syntax. You might want to collect {{ request.user }} into a variable and then use it in the dictionary.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜