AJAX / Javascript无法更新网页
AJAX / Javascript fails to update webpage
我写了一些ajax代码,但它没有更新网页。它应该从文件夹中获取一个表单并替换网页上显示的表单。但是,当我按下链接到javascript的按钮时,根本没有发生任何事情。
Javascript:
function LoadManagerForm()
{
document.getElementById('insert_response').innerHTML = "Loading..."
nocache = Math.random()
http.open('get', '../forms/managerform.php?nocache='+nocache);
http.onreadystatechange = insertReply;
http.send(null);
}
function insertReply()
{
if(http.readyState == 4){
var response = http.responseText;
document.getElementById('insert_response').innerHTML = response;
}
网页:
<section class="grid col-three-quarters mq2-col-two-thirds mq3-col-full">
<h2>Login</h2>
<div id="insert_response">
<p class="warning">Are you a manager? <a onclick="javascript:LoadManagerForm()" class="button" href="javascript:void(0);">Click here to login!</a></p>
<form id="emplogin" class="contact_form" action="#" method="post" name="emplogin">
<ul>
<li>
<label for="store">Store ID:</label>
<input type="text" name="store" id="store" required class="required" >
</li>
<li>
<label for="email">Email:</label>
<input type="email" name="email" id="email" required placeholder="JohnDoe@GMail.com" class="required email">
</li>
<li>
<label for="password">Password:</label>
<input type="password" name="password" id="password" required class="required">
</li>
<li>
<button type="submit" id="submit" name="submit" class="button fright">Login</button>
</li>
</ul>
</form>
</div>
</section>
我建议你使用Jquery很简单:
包含在 HTML 中的 head 标签中:
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
然后通过以下方式更改您的 JavaScript 函数:
function LoadManagerForm()
{
document.getElementById('insert_response').innerHTML = "Loading..."
nocache = Math.random();
$.post(
'../forms/managerform.php?nocache='+nocache,
{
nocache : nocache
},
function(response)
{
document.getElementById('insert_response').innerHTML = response;
}
);
}
相关文章:
- 如何在不退出javascript的情况下从javascript更新网页
- 使用JavaScript更新网页,无需重新加载网页
- 更新网页上Web服务器程序的实时输出
- 使用XML文件不断更新网页
- 更新网页上的计时器,并保持经过的时间--如何处理
- 使用 PHP 更新网页的一部分
- 使用 XMLHttpRequest 更新网页上的 API 内容
- 播放框架:从下拉列表中选择值时更新网页
- 缓存清单更新网页(如果联机)
- 如何更新网页中的许多链接
- 动态更新网页上的图形
- 在不重新加载整个页面的情况下更新网页的特定区域
- 您是否知道一个JavaScript库,它可以让您嵌入实时更新网页格式的文本区域
- 我的PlayFramework Action在Future准备就绪之前返回,如何更新网页组件
- d3.选择不更新网页中的图表
- AJAX / Javascript无法更新网页
- 从重定向页面返回时如何更新网页
- 如何在没有服务器端脚本访问的情况下进行实时更新网页
- 使用什么技术可以在不刷新网页的情况下更新网页内容?
- 使用jQuery更新网页.为什么这段代码不能工作?