簡體   English   中英

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;

想法是使用要傳輸到php腳本的數據創建一個字符串:

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

然后,如果沒有錯誤,則調用一個Ajax函數,該函數通過將字符串發送到服務器來發送。

查看有關以下內容的教程: 帶有POST和PHP的AJAX

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM