<分区>
我正在尝试在我的项目中添加图像上传功能,我想在单击按钮时调用 jquery 函数。但我不断在控制台中收到此错误:
Uncaught TypeError: image is not a function at HTMLButtonElement.onclick
这是我的按钮:
<button id="upload" value="Change the picture" onclick="image()">Change the picture</button>
这是我驻留在 js 文件中的 jquery 函数:
function image() {
var file_data = $('#file').prop('files')[0];
var form_data = new FormData();
form_data.append('file', file_data);
$.ajax({
url: 'index.php/welcome/upload_image' + '/' + ID, // point to server-side controller method
dataType: 'text', // what to expect back from the server
cache: false,
contentType: false,
processData: false,
data: form_data,
type: 'post',
success: function (response) {
$('.messages').html(response); // display success response from the server
},
error: function (response) {
$('.messages').html(response); // display error response from the server
}
});
});
PS:我在我的项目中使用 CodeIgniter。