you are looking for
$.get("/addtag.php", { tag_content: ui.tag });
or
$.get("/addtag.php", { tag_content: ui.tagLabel });
Frage
I'm using Tag-it, and I'm trying to save the added tags into my database (with ajax and php). This is what I got:
$(document).ready(function() {
$("#myTags").tagit({
afterTagAdded: function(event, ui) {
$.get("/addtag.php", { tag_content: "TAG_CONTENT" });
}
});
});
addtag.php:
$TAG_CONTENT = $_GET["tag_content"];
mysql_connect("xxx", "xxx", "xxx") or die(mysql_error());
mysql_select_db("xxx") or die(mysql_error());
$query = sprintf("INSERT INTO test (tags) VALUES ('%s');", $TAG_CONTENT);
mysql_query($query);
But how can I save the "real" tag? How do I get the value? Right now it, ofc, just saves the string "TAG_CONTENT"
Thanks in advance.
Lösung
you are looking for
$.get("/addtag.php", { tag_content: ui.tag });
or
$.get("/addtag.php", { tag_content: ui.tagLabel });
Andere Tipps
I know that this is an old question but maybe there are more people with this problem.
I was facing the same problem few minutes ago and and I was trying to use this with multiple input fields. So, I solved with the below approach:
function updateTags(answerId, data) {
$.post("/api/v1/tags/ + answerId + "/tags", data, function(data, status) {
});
}
$(".list-tags").tagit({
fieldName: 'tags[]',
placeholderText: 'Add Tag',
afterTagAdded: function(event, ui) {
if(! ui.duringInitialization) {
var form = $(this).parent();
var answerId = $(form).attr('data-id');
updateTags(answerId, $(form).serialize());
}
},
afterTagRemoved: function(event, ui) {
var form = $(this).parent();
var answerId = $(form).attr('data-id');
updateTags(answerId, $(form).serialize());
}
});
<form class="form-tags" data-id="{{myObject.id}}">
<ul class="list-tags"></ul>
</form>