javascript ajax,表单提交然后页面加载
javascript ajax, form submission then page load
我正在尝试使用javascript验证表单。一旦执行了下面的代码,我想从外部脚本中获取php,以便在没有页面加载的情况下运行,并在之后显示成功消息。有人能帮忙吗?
下面的脚本运行良好,并从一个单独的函数中提取notEmpty。我需要脚本,然后:1.如果没有产生错误,则提取php并从列出的每个值中传输数据。2.显示成功消息
var year = document.getElementById('year');
var period = document.getElementById('period');
var live = document.getElementById('live');
var start = document.getElementById('start');
var todate = document.getElementById('todate');
var sdeadline = document.getElementById('sdeadline');
var cdeadline = document.getElementById('cdeadline');
var circ = document.getElementById('circ');
var line = document.getElementById('line');
// Check each input in the order that it appears in the form!
if(notEmpty(year, "Please fill in Year")){
if(notEmpty(period, "Please fill in Period")){
if(notEmpty(live, "Please fill in live Date")){
if(notEmpty(start, "Please fill in Start Date")){
if(notEmpty(todate, "Please fill in End Date")){
if(notEmpty(sdeadline, "Please fill in Supplier Deadline")){
if(notEmpty(cdeadline, "Please fill in Commerical Deadline")){
if(notEmpty(circ, "Please fill in Circulars Due")){
if(notEmpty(line, "Please fill in Line Listing Downloads")){
}}}}}}}}}
return false;
ideea是用要传输到php脚本的数据创建一个字符串:
var datasend = 'year='+year+'&period='+period+'&live='+live+ ...;
然后,如果没有错误,调用一个Ajax函数,该函数通过Post将字符串发送到服务器。
请参阅关于以下内容的教程:AJAX with POST and PHP
相关文章:
- AngularJS加载JSON数据,然后从中解析/加载HTML
- 先在Angular中加载配置文件,然后再加载其他文件
- 加载文件,然后调用回调函数
- 如何更改javascript的一个变量,然后运行;“加载”;而无需重新加载页面
- 下拉重新加载页面,然后检索值
- 先加载特定的图像,然后再加载页面的其余部分
- 加载页面,然后在页面加载时执行 javascript
- Angular js,在选择元素上,我想 POST 数据以将其保存在数据库中,然后我想使用 PUT 更新它而无需重新加载
- 使用 jQuery 加载 JSON,然后将其显示给查看器
- 淡出加载然后淡入不起作用
- 可以进行现场重新加载,然后触发点击功能
- 在RadWindow中加载新页面,然后从加载的窗体中关闭窗口
- 加载在JSBN中创建的RSA公钥,然后加密消息
- 加载时可以单击按钮#1,然后需要单击按钮#2两次.按钮#1也需要点击两次
- 地图,rails 4.2,javascript,鼠标悬停,只工作一次(或两次).然后在重新加载之后
- 如何在jQuery中进行页面加载,然后点击
- removeChild,然后再次添加以前删除的Child以重新加载并清理它
- jQuery UI#Accordion加载然后fadeIN..怎样
- 中间的页脚加载然后粘在底部
- 加载然后换行,但是换行在jQuery中不起作用