如何使用OnComplete?

时间:2013-05-08 09:04:36

标签: javascript

我正在尝试使用发送电子邮件的Javascript / AJAX函数(使用PHP页面)。

功能是:

new Request({
    method: "post",
    data: this,
    onRequest: function() {
      $('amCallMeBackForm').empty().addClass('amCallMeBackWait');
      $('callback').setStyle('background', 'url(\'http://www.mysite.it/modules/mod_amcallmeback/assets/sfondo_callback.png\') no-repeat transparent');
      $('callback').setStyle('height', '73px');
    },
    onComplete: function(response) {
        $('amCallMeBackForm').removeClass('amCallMeBackWait');
        $('amCallMeBackForm').addClass('amCallMeBackSent');
        alert(response);
    }
}).send();
});

它工作正常,但我无法管理PHP页面的响应,我有这段代码:

<?php 
class modAmCallMeBackHelper
{

function send($params) {
    // Check for request forgeries
    JRequest::checkToken() or die( 'Invalid Token' );
            // get data
    $name =     JRequest::getVar('name', '');
    $rif =      JRequest::getVar('rif', '');
    $phone =    JRequest::getVar('phone', '');
    $uri =      JRequest::getVar('uri', '');

            // get module params
    $subject =  $params->get('mail_subject');
    $reciptient =   explode(',', $params->get('receipt_email'));
    $app =      JFactory::getApplication();
    $sender =   array($app->getCfg('mailfrom'), $app->getCfg('fromname'));

            // make email
    $Body = '<strong>Azienda:</strong> '.$name."<br />";
    $Body .= '<strong>Riferimento:</strong> '.$rif."<br />";
    $Body .= '<strong>Numero di telefono:</strong> '.$phone."<br />";
    $Body .= '<strong>Pagina da cui &egrave; stato richiesto il contatto:</strong> <a href='.$uri.'>'.$uri."</a>";

    $mailer =& JFactory::getMailer();
    $mailer->setSender($sender);
    $mailer->addRecipient($reciptient);
    $mailer->setSubject($subject);
    $mailer->isHTML(true);
    $mailer->Encoding = 'base64';
    $mailer->setBody($Body);
    if ($name == '' || $rif == '' || $phone == '' || $name == 'Azienda' || $rif == 'Riferimento' || $phone == 'Telefono') {
    } else {
    $send =& $mailer->Send();
    }

    if ($send != true) {
      return 'no';
    } else {
      return 'ok';
    }
}

    }
    ?>

当显示警告(响应)时,我可以从页面看到整个html代码(包括在内),但我无法仅显示PHP页面中的“返回”。

我做错了什么?

您可以在此处查看我的问题示例:http://www.sevenit.it(请在3秒后检查页面右上角)

由于

1 个答案:

答案 0 :(得分:1)

alert(response.responseText);  

将是我相信的方式。

编辑: 或者您可能想要做的是:

$('#amCallMeBackForm').html(response.responseText)

不是100%肯定你在问什么。