Javascript 上传特定图片,而不是提交完整表单
我有一个表单名editdata.php。使用大约10个html控件(文本框、文件、选择)。我有一个文件控件,用户的图片正在显示,下面是一个文件控件,用于更改图片。我想,当用户浏览,然后改变图片图片将自动改变,但形式不会提交。那么,这是否可以在不提交完整表单的情况下上传图片呢Javascript 上传特定图片,而不是提交完整表单,javascript,php,html,Javascript,Php,Html,我有一个表单名editdata.php。使用大约10个html控件(文本框、文件、选择)。我有一个文件控件,用户的图片正在显示,下面是一个文件控件,用于更改图片。我想,当用户浏览,然后改变图片图片将自动改变,但形式不会提交。那么,这是否可以在不提交完整表单的情况下上传图片呢 <html> <head> <meta charset="UTF-8"> <html lang="en"> <meta name="view
<html>
<head>
<meta charset="UTF-8">
<html lang="en">
<meta name="viewport" content="width=device-width, initial-scale=1"> <!--requuired for bootstrap -->
<link rel="stylesheet" href="Bootstrap/bootstrap.min.css" /> <!--bootstrap files -->
<script src="Bootstrap/jquery.min.js"></script>
<script src="Bootstrap/bootstrap.min.js"></script>
<style>
.error
{
color: red;
}
</style>
<title></title>
</head>
<body>
<div class="container">
<h1>Login Form</h1>
<h2><?php if(isset($_REQUEST['msg'])) echo $_REQUEST['msg'] ?></h2> <!-- Successful messgaeg if chnaged password -->
<form action="index.php" method="post" onsubmit="return checkData()" role="">
<div class="form-group">
<label>Username*</label>
<div><input type="text" class="form-control" id="uname" value="<?php if(isset($un)) echo $un; ?>" name="uname" onblur="setTimeout(function abc(){check_login_data('uname erruname blur', 'Username Must Be Entered')},130)" onfocus="check_login_data('uname erruname focus')" placeholder="Enter Username" /> <!-- textbox for username and checking value for cookie -->
</div>
</div>
<span class="error" id="erruname"> <?php if (isset($errorforusrnam)) echo $errorforusrnam; ?> </span> <!-- set a span for displaying error on emplty textbox -->
<div class="form-group">
<label>Password*</label>
<div><input type="password" class="form-control" id="password_id" name="upass" value="<?php if(isset($up)) echo ($up); ?>" placeholder="Enter Password" onblur="setTimeout(function abc(){check_login_data('password_id errpassword blur','Password Should Entered')},130)" onfocus="check_login_data('password_id errpassword focus')" /> <!-- textbox for Password and checking value for cookie -->
</div>
</div>
<span class="error" id="errpassword"> <?php if(isset($errorforpwd)) echo $errorforpwd ?> </span> <!-- set a span for displaying error on emplty textbox -->
<?php
if(isset($_SESSION['counter']) && $_SESSION['counter']>3) //captcha will show if user attempts more then 3
{
echo "<div class=form-group >"; //div for captcha
echo "<label for=captcha >Captcha*</label>";
echo "<div id=captcha_id>";
echo "<img id=imgCaptcha class=img-responsive src=captcha/create_image.php >";
echo '</div>';
echo '<div>';
echo "<div>";
echo "<input id=txtCaptcha class=form-control type=text name=txtCaptcha value='' placeholder='Enter Verification Code' />";
echo "<div><input class=btn btn-default type=button onclick=change_captcha() value=Reload /></div>";
echo "</div>";
echo "</div>";
echo "</div>"; //end of div
echo "<span class =error id=errco>"; //this will show error of div
if(isset($error))
{
echo $error;
}
echo '</span>';
}
?>
<div class="checkbox">
<label><input type="checkbox" name="chq" value="">Remember Me</label>
</div>
<div>
<input type="submit" name="sub" value="Login"class="btn btn-default" />
<a href="signup.php" />Signup</a>
<a href="forget_password.php" >Forgot Password</a>
</div>
<!-- <span id="span" ></span> span for showing output -->
</form>
</div>
</body>
</html>
.错误
{
颜色:红色;
}
登录表单
用户名*
经历这一切也许对你有帮助,
对ajax上传做一些研究
alredy尝试太多了干什么?有很多教程和插件脚本可用。我们不知道您在实施它们时遇到了什么问题