douxian0279 2017-07-12 09:13
浏览 41
已采纳

ajax表单警报(jQuery)

I have a problem with ajaxform. I have a php file called captcha.php that it generates a captcha:

<?php
session_start();

$random_number =  rand(1,9).rand(1,9).rand(1,9).rand(1,9).rand(1,9).rand(1,9);
$_SESSION['captcha_text'] = $random_number;

$captcha_image = imagecreatefromjpeg("captcha.jpg");
$font_color = imagecolorallocate($captcha_image, 0, 0, 0);
imagestring($captcha_image, 5, 20, 5, $random_number, $font_color);
imagejpeg($captcha_image);
imagedestroy($captcha_image);
?>

I have another php file called pro.php that it is executed on action form and send an e-mail with form's data:

<?php
session_start();
@extract($_POST);
$sub = "Curriculum di: ".stripslashes($name);
$message = stripslashes($messaggio);
$fromail = stripslashes($email);
$attachment = chunk_split(base64_encode(file_get_contents($_FILES['file']['tmp_name'])));
$filename = $_FILES['file']['name'];
$boundary =md5(date('r', time())); 
$headers = "From: ".$fromail;
$headers .= "
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary=\"_1_$boundary\"";
$message="This is a multi-part message in MIME format.
--_1_$boundary
Content-Type: multipart/alternative; boundary=\"_2_$boundary\"
--_2_$boundary
Content-Type: text/plain; charset=\"iso-8859-1\"
Content-Transfer-Encoding: 7bit
$message
--_2_$boundary--
--_1_$boundary
Content-Type: application/octet-stream; name=\"$filename\" 
Content-Transfer-Encoding: base64 
Content-Disposition: attachment 
$attachment
--_1_$boundary--";
if(isset($_POST['txtCaptcha']) and $_POST['txtCaptcha'] !='')
   if($_SESSION['captcha_text'] == $_POST['txtCaptcha'])
       mail('myemail@myemail.it', $sub, $message, $headers);
?>

Now I would like to show an alert if the email was sent correctly or not:

<script> 
  $(document).ready(function() { 
    $('#myFormId').ajaxForm(function() {
          //Instructions to enter
    }); 
  }); 
</script> 

What's the solution? (Sorry for my bad english)

  • 写回答

1条回答 默认 最新

  • duan0504 2017-07-12 09:20
    关注

    You have to call success param:

    $("your-form").ajaxForm({
        success: function(res, status, xhr, form) {
            // ... call the alert
        }
    });
    

    Good coding.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 使用C#,asp.net读取Excel文件并保存到Oracle数据库
  • ¥15 C# datagridview 单元格显示进度及值
  • ¥15 thinkphp6配合social login单点登录问题
  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配