我正在尝试使用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;
答案 0 :(得分:0)
ideea是创建一个包含您想要传输到php脚本的数据的字符串:
var datasend = 'year='+year+'&period='+period+'&live='+live+ ...;
然后,如果没有错误,则调用一个Ajax函数,通过Post将字符串发送到服务器。
查看有关以下内容的教程:AJAX with POST and PHP