0

我正在尝试使用 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;
4

1 回答 1

0

想法是创建一个字符串,其中包含要传输到 php 脚本的数据:

var datasend = 'year='+year+'&period='+period+'&live='+live+ ...;

然后,如果没有错误,则调用 Ajax 函数,通过 Post 将字符串发送到服务器。

请参阅有关以下内容的教程:AJAX with POST and PHP

于 2012-07-10T11:48:32.137 回答