Php codeginter中我的ajax或jquery中的问题
brother I insert image edit update工作正常,但我的问题是,当我单击edit并删除一些图像时,这是ajax调用,但它会出现一些错误,我不知道为什么会显示此错误brother帮助我提前谢谢 这是我的编辑代码-Php codeginter中我的ajax或jquery中的问题,php,jquery,ajax,Php,Jquery,Ajax,brother I insert image edit update工作正常,但我的问题是,当我单击edit并删除一些图像时,这是ajax调用,但它会出现一些错误,我不知道为什么会显示此错误brother帮助我提前谢谢 这是我的编辑代码- <span style="cursor:pointer;" onclick="javascript:deleteimage(<?php echo $data['id'] ?>)">X</span>
<span style="cursor:pointer;" onclick="javascript:deleteimage(<?php echo $data['id'] ?>)">X</span>
</td>
</tr>
<?php }endif; ?>
<tr>
<td>Images</td>
<td><input type="file" name="userfile[]" id="image_file" accept=".png,.jpg,.jpeg,.gif" multiple></td>
</tr>
<tr>
<td colspan="2" align="center"><input style="width: 50%;" type="submit" value="Submit"></td>
</tr>
</table>
</form>
<script>
$(document).ready(function() {
function deleteimage(image_id) {
var answer = confirm("Are you sure you want to delete from this post?");
if (answer) {
$.ajax({
type: "POST",
url: "<?php echo site_url('welcome/deleteimage');?>",
data: "image_id=" + image_id,
success: function(response) {
if (response == 1) {
$(".imagelocation" + image_id).remove(".imagelocation" + image_id);
};
}
});
}
}
});
</script>
我的错误是
未捕获引用错误:未定义deleteimage
在HTMLSpanElement.onclick VM1166 5:35
尝试更改此选项:
onclick="javascript:deleteimage(<?php echo $data['id'] ?>)
为此:
onclick="deleteimage(\"<?php echo $data['id'] ?>\")
并将该函数移到文档外。就绪这是正确答案
<script>
function deleteimage(image_id) {
var answer = confirm("Are you sure you want to delete from this post?");
if (answer) {
$.ajax({
type: "POST",
url: "<?php echo site_url('welcome/deleteimage');?>",
data: "image_id=" + image_id,
success: function(response) {
if (response == 1) {
$(".imagelocation" + image_id).remove(".imagelocation" + image_id);
};
}
});
}
}
</script>
谢谢各位兄弟我自己解决了这个错误是这个$document.readyfunction{我删除了这个函数它工作得很好,你也可以使用更短的版本@AlivetoDie brother这些在2天后显示警报我可以标记这个如果你同意我的ans请标记这个