ssharma
ssharma

Reputation: 349

Pass a list through Ajax in Django

I have made an Ajax call:

$.ajax({
              url:'/quespaper/intermediate_table',
              type:'GET',
              processData: false,
              data:{'url_link':url_link_copy,'updated_url_link':er},
               success: function(data){ alert('Urls updated');},
               error:function(error){
                 alert(error);
                 console.log(error);
               }
            });

Here,url_link_copy is a list,which is being properly printed at the console and er is the collection of value of all text boxes:

var er = $(".form-control.input-sm").val();

The mapping to a views.py function is correct,but,in that function,when I print the data,it prints:None.

I tried JSON.stringify also:

data:JSON.stringify({'url_link':url_link_copy,'updated_url_link':er})

But,it also didn't work.

Please suggest what is wrong in this implementation.

Thanks.

Upvotes: 0

Views: 1015

Answers (1)

badiya
badiya

Reputation: 2257

use getlist() function of the get request object. So instead of

url_link = request.GET.get('url_link')

try

url_link = request.GET.getlist('url_link')

Upvotes: 3

Related Questions