I have 2 forms within the same template. One adds Country tags to a current users profile, the other adds Interest tags. Both forms are bring posted to the same url. Both tag fields are filtered through an autocomplete so both fields have their corresponding content. Country input will return a list of Countries, etc.
When I search through the Country Tag field, I'm able to add a country tag. Awesome! However, when trying to add an Interest, the spinner.gif is activated, but within my console the post returns a 404 and therefore doesn't add the actual interest tag.
Template: The other form is the same, just replace the ids: Country
with Interest
.
<form id="addCountryTagForm" class="add_tags_form" method="POST" action="/tag/add/">
{% csrf_token %}
<input id="country-tag-input" class="input-text inline required tag-select" name="tagname" type="hidden" />
<button class="btn addtag" type="submit" id="addCountryTag">
<span>Add</span>
</button>
</form>
ajax:
$('.add_tags_form').submit(function(e) {
var $this = $(this);
var $loader = $('<div class="tag-loader"><img src="/static/images/misc/spinner.gif" /></div>');
$this.append($loader);
e.preventDefault();
var action = $this.attr("action");
result = $.ajax({
url: action,
data: {
'csrfmiddlewaretoken':$('input[name^="csrfmiddlewaretoken"]').val(),
'tagname':$('input[name^="tagname"]').val()
},
type: "POST",
success: function(data) {
$('.tag-section').load('/account/tag-section/');
$('input[name^="tagname"]').val('');
$loader.remove();
},
error: function(jqXHR, textStatus, errorThrown) {
$loader.remove();
}
});
return false;
});
I really don't know why this isn't working. Is what I'm trying to accomplish unattainable? Can 2 forms posting to the same url not work within the same template? If anyone could offer inisight, it would be greatly appreciated.