我想用 j子立立案,而不使用任何PLUGIN。
JQuery对我来说是很新的,在我研究各种论坛之后,我最后通过了这一法典:
HTML:
<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript" charset="utf-8">
$(document).ready(function(){
$( #myform ).submit(function() {
var fileInput = document.getElementById( file );
var file = fileInput.files[0];
var formData = new FormData();
formData.append( file , file);
$.ajax({
type: "POST",
url: "upload.php",
data: formData,
processData: false,
contentType: multipart/form-data ,
beforeSend: function (x) {
if (x && x.overrideMimeType) {
x.overrideMimeType("multipart/form-data");
}
},
success:function(msg){
//alert( "Data Uploaded: " + msg );
document.getElementById( display ).innerHTML = msg;
}
});
return false;
});
});
</script>
</head>
<body>
<form enctype="multipart/form-data" id="myform" name="myform" method="POST">
<input name="file" type="file" id="file" name="file"/>
<input type="text" name="txtValue" value="" id="txtValue">-->
<input type="submit" value="Upload" id="button" name="button"/>
<div id="display"></div>
</form>
</body>
</html>
PHP:
<?php
$uploaddir = ./uploads/ ;
$file = $uploaddir . basename($_FILES[ file ][ name ]);
if (move_uploaded_file($_FILES[ file ][ tmp_name ], $file)) {
$value = "success";
}
else {
$value = "error";
}
echo $value;
?>
该守则没有发挥作用,每当“显示”数字四印刷“探测器”。 请帮助我。