我得到<img>
用户应该能够点击(例如删除墙上的帖子)。每张图片都有“imageid
”,与文章本身的ID匹配。现在我想通过这个“imageid
”通过JavaScript/jQuery /无论我的delete.php
文件,我发送该ID到我的Oracle数据库知道要删除的文章。通过POST从<img>传递特定值到PHP
IMGS样子:
<img alt="Delete Article" src="include/images/delete.png" imageID="21" title="Delete Article">
和JavaScript:
$(document).ready(function erase() {
$("img[title='Delete Article']").click(function() {
if (confirm("Are you sure?")) {
var image = $(this).data('imageID');
$.ajax({
type: "POST",
url: 'include/site/delete.php',
data: 'imageID=' + image,
});
}
});
});
我才发现创建一个隐藏的表单标签,并把它这样的方式,但我想这样做(如果可能)以另一种方式:)
在此先感谢
找到解决方案!
$(document).ready(function() {
$("img[title='Delete Article']").click(function() {
if (confirm("Are you sure?")) {
var getimageID = $(this).attr('imageID');
$.post("include/site/delete.php", {
catchedID : "ID ist " + getimageID
});
}
});
});
可能的重复[如何使用jQuery POST将变量从JavaScript传递到PHP](http://stackoverflow.com/questions/2376913/how-to-pass-variable-from-javascript-to-php-using- jquery-post) – 2013-04-22 11:50:26
(请注意,这个具体问题在你如何做事情方面比你先行一步) – 2013-04-22 11:50:43
最好使用有效的'data- *'属性来代替。 'data-imageid'应该替换'imageid'。 – Mooseman 2013-04-22 11:51:51