javascript - 在同一个表单页面中成功提交表单后如何显示图像?
问题描述
我创建了一个包含表单的页面,我想在成功提交表单后显示隐藏在同一页面中的图像,我正在尝试使用 PHP 代码中的 JavaScript 来实现。
这是代码
html代码:
<label for="UserEmail">Email</label>      
<input type="text" name="UserEmail" placeholder="Enter Email"><br><br>
<label for="UserEmail">Password</label>
<input type="password" name="UserPass" placeholder="Enter Password"><br><br>
<input type="submit" value="Log in">  
<button>click</button>
<a href="securityQ.html">Forgot password</a>  
<a href="register.html">New !! register </a>
<div id="imge">
<img src="profile.png" alt="Profile Image">
</div>
</form>
PHP代码:
<?php
error_reporting(0);
$x ="hi";
$y ="1";
if(($_POST["UserEmail"]==$x) and ($_POST["UserPass"]==$y))
{
echo "<script>
document.getElementById('img').style.display='block';
</script>";
header("location: index.html");
}
else {
echo "<script>alert('Login Faild');window.location.href='index.html';</script>";
}
?>
解决方案
你必须使用jQuery和ajax来提交表单,当你提交表单并在数据库中插入数据并将图像上传到文件夹中时,然后返回该图像的位置,在jQuery的成功方法中,使用该图像位置来显示使用 jQuery 选择器在任何特定元素上显示图像并使该元素可见
推荐阅读
- r - 纵向数据集中的折叠行
- java - Azure 应用服务上的 Tomcat Web-App 404-0 错误
- arrays - TensorFlow 中这个 Numpy 代码的等价物是什么?
- c# - ExecuteReader 抛出 ORA-01840 但来自 sqlDeveloper 运行良好
- couchdb - CouchDB芒果忽略索引排序顺序
- corda - 更新状态的子关系行的最佳实践是什么?
- python-3.x - 如何让我的程序在循环的每次迭代中选择一个新的随机数?- 魔术 8 球
- android - 更新后“所有 com.android.support 库必须使用完全相同的版本规范”
- javascript - 按父 ID 递归搜索后代
- solr - 从 C# 访问 Solr 8