我使用 jQuery 读取字符串并将其传递给 PHP,然后插入/编辑数据库。 我的问题是,在此过程中,我丢失了大字符串,它们永远不会保存到数据库,而且我无法编辑它们!我有一个很大的字符串,我无法编辑它。代码崩溃了!
:eq() 选择器对字符串大小有限制吗?!
我选择字符串的代码是:
$(document).on("click",".edit_button",function() {
$(this).parents("tr").each(function(index) {
$("*").css("cursor", "wait");
id = $(this).find("td").eq(0).text();
comment = $(this).find("td").eq(1).text();
$.ajax({
type: 'GET',
url: 'ajax.php',
data:{ comment : comment , job : "edit"},
dataType:"html",success:function(result){
$("*").css("cursor","auto");
$(".edit_button").css("cursor", "pointer");
document.getElementById("items_body").innerHTML=result;
}
});
});
});
文件ajax.php中的PHP代码是:
$job=$_GET["job"];
if ($job=="edit")
{
$comment=$_GET["comment"];
$id=$_GET["id"];
$sql_command="UPDATE items SET comment='$comment' WHERE id='$id'";
mysql_query($sql_command,$con);
}
最佳答案
您没有在 ajax 调用中传递 id
data:{ comment : comment , job : "edit", id : id },
There is no limitation for
eq()
, limitation is for get method. So it's better to use post instead.
关于javascript - 使用 :eq() Selector 时字符串丢失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30411293/