将图像从php发布到javascript
我尝试使用php将我的php代码转换为javascript ajax。由于我的php代码仍然处于激活状态,您能纠正我应该出了什么问题吗 html代码:将图像从php发布到javascript,javascript,php,jquery,ajax,Javascript,Php,Jquery,Ajax,我尝试使用php将我的php代码转换为javascript ajax。由于我的php代码仍然处于激活状态,您能纠正我应该出了什么问题吗 html代码: <form method="post" enctype="multipart/form-data" action="testadd.php"> <input type="file" name="image" id="image"> <br/> <input type="submit" name="subm
<form method="post" enctype="multipart/form-data" action="testadd.php">
<input type="file" name="image" id="image">
<br/>
<input type="submit" name="submit" value="upload" id="submit">
</form>
请检查问题所在,以便修复。AJAX必须具有内容类型、处理数据才能上载图像文件
$.ajax({
url: 'Your url here',
data: formData,
type: 'POST',
// THIS MUST BE DONE FOR FILE UPLOADING
contentType: false,
processData: false,
// ... Other options like success and etc
success : function(data){
//Do stuff for ahed process....
}
});
在谷歌上搜索一次,你会问…你认为我没有搜索谷歌吗?如果我不在谷歌上搜索,为什么我会在这里问?我只想维护我写的代码,因为在谷歌有很多方法可以做到这一点。我只想知道和我写的相同的代码有什么问题。有几个人已经问了和你一样的问题,这就是为什么我告诉谷歌在提问之前先做
$(document).ready(function(){
$("#submit").click(function(){
var image = document.getElementById("image").value;
alert(" " + image);
if(image == ""){
alert("please select image");
}else{
$.ajax({
type: "POST",
url: "testadd.php",
data: "image=" + image,
success: function(data){
if(data == success){
alert("test");
}else{
alert("fail");
}
}
});
}
return false;
});
});
$.ajax({
url: 'Your url here',
data: formData,
type: 'POST',
// THIS MUST BE DONE FOR FILE UPLOADING
contentType: false,
processData: false,
// ... Other options like success and etc
success : function(data){
//Do stuff for ahed process....
}
});