1 回答
TA贡献1982条经验 获得超2个赞
HTML 页面 :-
将button属性值更改为type="button"而不是type="submit"&添加onclick事件属性。
<form id="descriptionsubmit" action="" method="post" enctype = "multipart/form-data">
<textarea class="form-control" name="textarea-description" placeholder="Write Something"></textarea>
<input type="file" name="upload-pic" id="upload-pic" class="inputfile" >
<button type="button" onclick="addData()" class="update-btn">Next</button>
</form>
JS AJax 代码:-
function addData() {
var formData = new FormData($('#descriptionsubmit')[0]);
formData.append('action', 'add');
$.ajax({
method: 'post',
processData: false,
contentType: false,
cache: false,
enctype: 'multipart/form-data',
url: 'AJAXSubmitClientData.php',
data: formData,
success:function(msg){
alert(msg);
}
});
}
AJAXSubmitClientData.php
<?php
include('dbconn.php');
if(isset($_POST["action"]) && $_POST["action"]=="add"){
echo $a = $_POST["textarea-description"];
echo $g = $_FILES["upload-pic"]["name"];
// insert code here.
}
?>
- 1 回答
- 0 关注
- 93 浏览
添加回答
举报