我不是为什么我得到一个未定义索引的错误。我想我正确地将值发送到PHP。或者我在代码中丢失了什么?为什么我得到一个未定义索引的错误我正在使用jquery ajax
这里是jQuery代码我使用:
$(function() {
$('button').button();
$('.update-profile-pic').click(function() {
$('#dialog').dialog({
width:350,
modal:true,
buttons: {
'Upload': function() {
$.ajax({
url: 'upload-image.php',
method: 'post',
data: { uploadedfile: $('.profile-pic-name').val().trim() },
success: function(data) {
$('.new-profile-pic').html(data);
}
});
}
}
});
});
});
这里是我的html代码:
<button class="update-profile-pic">Update Profile Picture</button>
<div id="dialog">
<p class="new-profile-pic">
<!--Image should be here-->
</p>
<form enctype="multipart/form-data">
<input type="hidden" name="MAX_FILE_SIZE" value="100000">
<input class="profile-pic-name" name="uploadedfile" type="file">
</form>
<div>
这是我的PHP代码:
<?php
$target_path = "uploads/";
$target_path = $target_path . basename($_FILES['uploadedfile']['name']);
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
echo '<img alt="" src="'.$target_path.'">';
} else{
echo "There was an error uploading the file, please try again!";
}
?>
这里的萤火虫的控制台的结果点击上传后:
这里的抽样误差输出中:
可能重复[我如何可以上传文件异步使用jQuery?](http://stackoverflow.com/questions/166221/how-can-i-upload-files-asynchronously -with-jquery) – DCoder
使用你的浏览器调试工具错误发生在哪一行?例如,当使用Chrome浏览器时,会列出错误信息以及在哪些文件中出现的信息以及哪些行等信息。我相信其他浏览器的工具是相似的。 – Nope
我在我的回应标签中使用萤火虫它说undefined索引︰uploadedfile –