Edgar Navasardyan
Edgar Navasardyan

Reputation: 4501

Django - passing parameters to GET method when using JS window.open() function

I Have the following JS script which opens a new window and renders a Django template corresponding to /my_url/.

function draw_comparing_graphs()
{
    window.open('/my_url/', '_blank', 'location=yes,height=570,width=1500,scrollbars=yes,status=yes');  
}

Now, the question is, how do I pass on parameters to Django ? I mean, what is the equivalent of $.post('/my_url/', data)

Upvotes: 0

Views: 1000

Answers (1)

Wolph
Wolph

Reputation: 80031

Since you're just opening a page, using POST is not an easy option (you could by having it automatically submit a form from /my_url/, but I wouldn't recommend it). You could easily append some GET parameters to /my_url/ though. Something like: `/my_url/?json=...your-json-data...

Within Django you can reach this using request.GET['json']

Example with your code:

function draw_comparing_graphs()
{
    window.open('/my_url/?json=' + encodeURIComponent(json_data), '_blank', 'location=yes,height=570,width=1500,scrollbars=yes,status=yes');  
}

Upvotes: 1

Related Questions