Reputation: 2320
In my Django project I have a ajax search which returns a list of results along with button "Add"
What I want:
Work p. 1-2 but not 3
jquery-ajax
$(document).on('click', '.button-add', ->
catid = $(this).attr("data-catid")
title = $(this).attr("data-title")
url = $(this).attr("data-url")
$.get('/test/auto_add_page/', {category_id:catid, title:title, url:url}, (data) ->
$('#pages').html(data)
$(this).hide()
))
Upvotes: 1
Views: 83
Reputation: 599796
this
inside the get
now refers to a different object. Save it in a variable in the outer block and refer to that.
$(document).on('click', '.button-add', ->
button = $(this)
catid = button.attr("data-catid")
title = button.attr("data-title")
url = button.attr("data-url")
$.get('/test/auto_add_page/', {category_id:catid, title:title, url:url}, (data) ->
$('#pages').html(data)
button.hide()
))
Upvotes: 1