function ajax_post(){
// Create our XMLHttpRequest object
var hr = new XMLHttpRequest();
// Create some variables we need to send to our PHP file
var url = "LiveUpdate.php";
var sb = document.getElementById("LiveUpdate").value;
var FirstName = document.getElementById("FirstName").value;
var images = document.getElementById("images").value;
var vars = "update="+sb+"&FirstName="+FirstName+"&images="+images;
hr.open("POST", url, true);
// Set content type header information for sending url encoded variables in the request
hr.setRequestHeader("Content-type", "multipart/form-data");
// Access the onreadystatechange event for the XMLHttpRequest object
hr.onreadystatechange = function() {
if(hr.readyState == 4 && hr.status == 200) {
var return_data = hr.responseText;
document.getElementById("message").innerHTML = return_data;
}
}
// Send the data to PHP now... and wait for response to update the status div
var formData = new FormData(document.querySelector("form"));
hr.send(formData); // Actually execute the request // Actually execute the request
document.getElementById("message").innerHTML = "processing...";
}
//show image before uploading
var loadFile = function(event) {
var output = document.getElementById('output');
output.src = URL.createObjectURL(event.target.files[0]);
};//end image
这就是表格。 JavaScript和表单在同一个文件中。文件名是sample.php
这段代码的想法是。我想插入像名字和图像的基本信息到数据库中而不刷新页面。我之所以选择标签来提交ajax。所以页面URL Account.php?Edit = 1不会更改为Account.php,因为如果它更改为account.php,则弹出式编辑模式将关闭。这个代码中的问题是。我不知道如何解决这个错误Warning: Missing boundary in multipart/form-data POST data in Unknown on line 0任何人都可以帮助我解决这个问题。谢谢!
+0
可能重复的[警告:缺少多行/表单数据POST数据在行0中未知的边界](http://stackoverflow.com/questions/27635738/warning-missing-boundary-in-multipart-form-data-post- data-in-unknown-on-line-0) –