Last active
July 17, 2019 15:11
-
-
Save jgram925/3a4be9a4ff7c46d8d5ecf764453c173b to your computer and use it in GitHub Desktop.
Ajax Post.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var pk_list = []; | |
$('#forecast_table').on('click', '#add_to_list', function(){ | |
var this_val = parseInt($(this).val()); | |
if($(this).html() == 'Add to List'){ | |
$(this).removeClass('btn-primary').addClass('btn-danger').html('Remove from List') | |
pk_list.push(this_val); | |
}else{ | |
$(this).addClass('btn-primary').removeClass('btn-danger').html('Add to List') | |
pk_list.splice($.inArray(this_val, pk_list), 1); | |
} | |
console.log(pk_list); | |
}); | |
$('#generate_asn').on('click', function(){ | |
SendPost(pk_list); | |
}); | |
function SendPost(pk_list){ | |
$.post("{% url 'create_asn_invoice' %}", | |
{pk_list: JSON.stringify(pk_list), csrfmiddlewaretoken: '{{csrf_token}}'} | |
).done(function(){ | |
console.log('POST worked!') | |
}).fail(function(){ | |
console.log('POST failed!') | |
}); | |
}; | |
// ON THE VIEW // | |
//def create_asn_invoice(request): | |
// if request.method == 'POST': | |
// pk_list_str = request.POST.get('pk_list') | |
// pk_list = json.loads(pk_list_str) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment