views:

32

answers:

2

Hi.

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 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...

+1  A: 

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.

Manoj Govindan
Why would the syntax conflict? Template variables are resolved before the page is sent to the client, so the javascript would only see the rendered variable.
Daniel Roseman
Thanks. My mistake. I was not thinking straight.
Manoj Govindan
+1  A: 

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/

Jason Leveille