将数据从 div 提交到数据库,其中(div)在附加 id 后获取数据
Submitting data from a div to database, which(div) is getting a data after appending a id
我知道它非常复杂,但我只是想做一个标签系统。我正在通过使用“@”首字母的 ajax 调用从数据库中获取数据。我可以做任何事情,甚至正在创建标签,但我无法获取这些标签并将它们提交到 table 标签下的数据库中。
<script type="text/javascript" src="http://ajax.googleapis.com/
ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function()
{
var start=/@/ig; // @ Match
var word=/@(\w+)/ig; //@abc Match
$("#text").live("keyup",function()
{
var content=$(this).text(); //Content Box Data
var go= content.match(start); //Content Matching @
var name= content.match(word); //Content Matching @abc
var dataString = 'searchword='+ name;
//If @ available
if(go.length>0)
{
$("#msgbox").slideDown('show');
$("#display").slideUp('show');
$("#msgbox").html("Type the name of someone or something...");
//if @abc avalable
if(name.length>0)
{
$.ajax({
type: "POST",
url: "boxsearch.php", // Database name search
data: dataString,
cache: false,
success: function(data)
{
$("#msgbox").hide();
$("#display").html(data).show();
}
});
}
}
return false();
});
//Adding result name to content box.
$(".addname").live("click",function()
{
var username=$(this).attr('title');
var old=$("#contentbox").html();
var content=old.replace(word," "); //replacing @abc to (" ") space
$("#contentbox").html(content);
var E="<a class=red contenteditable='false' href='#' >"+username+"</a>";
$("#contentbox").append(E);
$("#display").hide();
$("#msgbox").hide();
});
});
</script>
// Inserting data to database using ajax
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/
libs/jquery/1.3.0/jquery.js"></script>
<script type="text/javascript" >
$(function() {
$(".submit").click(function()
{
var contentbox = $("#contentbox").val();
var dataString = 'contentbox='+ contentbox;
if(contentbox.length < 1)
{
alert('It seems you havnot entered anything.');
}
else
{
$.ajax({
type: "POST",
url: "insert-tag.php",
clearForm: true,
data: dataString,
success: function(html){
$("ol#update-status").append(html);
$("ol#update-status li:last").fadeIn("slow");
$("#flash").hide();
document.getElementById("text").value = "";
}
});
}return false;
}); });
</script>
//HTML Code
<div id="container">
<div id="text" contenteditable="true"></div>
<div id='display'>
</div>
<div id="msgbox">
</div>
<br>
<br>
<div id="contentbox" >
</div>
<input type="submit" class="submit">
</div>
我知道它非常复杂,但我只是想做一个标签系统。我正在通过使用“@”首字母的 ajax 调用从数据库中获取数据。我可以做任何事情,甚至正在创建标签,但我无法获取这些标签并将它们提交到 table 标签下的数据库中。
<script type="text/javascript" src="http://ajax.googleapis.com/
ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function()
{
var start=/@/ig; // @ Match
var word=/@(\w+)/ig; //@abc Match
$("#text").live("keyup",function()
{
var content=$(this).text(); //Content Box Data
var go= content.match(start); //Content Matching @
var name= content.match(word); //Content Matching @abc
var dataString = 'searchword='+ name;
//If @ available
if(go.length>0)
{
$("#msgbox").slideDown('show');
$("#display").slideUp('show');
$("#msgbox").html("Type the name of someone or something...");
//if @abc avalable
if(name.length>0)
{
$.ajax({
type: "POST",
url: "boxsearch.php", // Database name search
data: dataString,
cache: false,
success: function(data)
{
$("#msgbox").hide();
$("#display").html(data).show();
}
});
}
}
return false();
});
//Adding result name to content box.
$(".addname").live("click",function()
{
var username=$(this).attr('title');
var old=$("#contentbox").html();
var content=old.replace(word," "); //replacing @abc to (" ") space
$("#contentbox").html(content);
var E="<a class=red contenteditable='false' href='#' >"+username+"</a>";
$("#contentbox").append(E);
$("#display").hide();
$("#msgbox").hide();
});
});
</script>
// Inserting data to database using ajax
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/
libs/jquery/1.3.0/jquery.js"></script>
<script type="text/javascript" >
$(function() {
$(".submit").click(function()
{
var contentbox = $("#contentbox").val();
var dataString = 'contentbox='+ contentbox;
if(contentbox.length < 1)
{
alert('It seems you havnot entered anything.');
}
else
{
$.ajax({
type: "POST",
url: "insert-tag.php",
clearForm: true,
data: dataString,
success: function(html){
$("ol#update-status").append(html);
$("ol#update-status li:last").fadeIn("slow");
$("#flash").hide();
document.getElementById("text").value = "";
}
});
}return false;
}); });
</script>
//HTML Code
<div id="container">
<div id="text" contenteditable="true"></div>
<div id='display'>
</div>
<div id="msgbox">
</div>
<br>
<br>
<div id="contentbox" >
</div>
<input type="submit" class="submit">
</div>