在codeigniter中我的ajax或jquery中的问题

brother I insert image edit update is working fine but my problem is that when I click edit and delete some image that is the ajax call but its give some error I don't know why this show this error any brother help form me advance thanks

this is my edit code-

        <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>

End show my error is

Uncaught ReferenceError: deleteimage is not defined at HTMLSpanElement.onclick (VM1166 5:35)

This is the correct answer

<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>

try to change this:

onclick="javascript:deleteimage(<?php echo $data['id'] ?>)

to this:

onclick="deleteimage(\"<?php echo $data['id'] ?>\")

And move the function outside the document.ready