我正在嘗試使用ajax技術(shù)發(fā)送數(shù)據(jù)。我制作了一個(gè) ajax_form.js 文件,負(fù)責(zé)此功能:$(document).ready(function(){ var name = $("#name").val(); var email = $("email").val(); var message = $("message").val();$("#push").submit(function(e){ // $("#push") is a button e.preventDefault(); $.ajax({ url: "../send.php", tpye: "POST", cache: false, data: { 'name': name, 'email': email, 'message': message }, dataType: 'html', beforeSend: function(){ $("#push").prop("disabled",true); }, succsess: function(data){ if(!data){ alert("ошибка при отправке данных"); } else{ $("#mail_form").trigger("reset"); alert(data); } $("push").prop("disabled", false); }, }) })}) 我制作了以下腳本 send.php,其中包含用于發(fā)送的變量和 mail() 函數(shù):<?php$name = $_POST['name'];$email = $_POST['email'];$message = $_POST['message'];$subject = "=?utf-8?B?".base64_encode("Заявка с сайта")."?=";$headers = "From: $email\r\nReply to: $email\r\nContent-type: text/html; charset=utf-8\r\n";$name = trim($name);$name = trim($email);if (isset($name) && isset($email) && isset($message)){ $success = mail("d.romanuk@mail.ru", $subject, $message, $headers); echo $success;}ini_set("display_errors","1");ini_set("display_startup_errors","1");ini_set('error_reporting', E_ALL);?>這里我有兩個(gè)問題:1)當(dāng)我單擊按鈕時(shí),頁面更新,并且郵件表單中的數(shù)據(jù)不發(fā)送;它不應(yīng)該更新網(wǎng)頁,因?yàn)槲艺谑褂胑.preventDefault() 2)而且我想我的網(wǎng)絡(luò)表單不起作用,因?yàn)樗鼞?yīng)該alert()在發(fā)送數(shù)據(jù)之后
頁面更新,當(dāng)我嘗試使用ajax+php發(fā)送mail-foem數(shù)據(jù)時(shí)
米脂
2023-06-29 22:43:53