我有Ajax并且它成功运行,但它没有显示成功消息而且它没有重新加载页面。在控制台中,它不仅返回'成功',还返回一些HTML。这是什么原因?这应该会引起问题。
我的控制台有以下内容:
success<html>
<head>
<link href='http://fonts.googleapis.com/css?family=Open+Sans:300italic,400,300,600,700&subset=latin,cyrillic' rel='stylesheet' type='text/css'>
<style>
.boldText,.boldText td{
font-family: 'Open Sans', sans-serif;
font-weight: bold !important;
}
//and some other html
Ajax是:
function sendQuoteMail() {
var send_options = $('input[name=send_options]:checked').val(),
offer_id = $("#SendQuoteMail").attr('data-offer-id'),
send_free_message = $("#send_free_message").val(),
atm = $("#alternative_transport_mode").val(),
lang = $("#selectlangoffer").val(),
options = [];
if(typeof atm != 'undefined' && atm != null && atm.length > 0 && atm != '') {
$('#quoteInfo .accordion-group').each(function () {
var id = $(this).attr('id');
id = id.substr(6);
options.push(id);
});
} else {
$("#quoteInfo input.addToGenerateOffer:checkbox:checked").each(function () {
options.push($(this).attr('data-id'));
});
}
if(options.length === 0) {
options = false;
}
console.log('Sent options: ' + options); //return;
$.ajax({
url: Base_URL + "/offers/preSendOffer",
type: "POST",
data: {
"offer_id": offer_id,
"send_options":send_options,
"send_free_message": send_free_message,
"lang": lang,
"atm": atm,
"options": options,
"quote_general_info_id": quoteData['quote_general_info_id']
},
success: function (data) {
if(data === 'success') {
MessageBoxOK(translate('Quote send successfully'));
window.location.reload();
}
},
error: function (data) {
MessageBoxError(translate('You don\'t have access to MyUnimasters Portal!'));
}
});
}
控制器是:
public function action_preSendOffer() {
$this->auto_render = false;
$change_statuses = true;
if($_POST) {
// print '<pre>'; print_r($_POST);exit;
$lang = isset($_POST['lang']) ? $_POST['lang']:$this->current_lang;
$atm = (!empty($_POST['atm']) AND in_array($_POST['atm'], array('ROA', 'AIR', 'LCL', 'FCL')))?$_POST['atm']:false;
//TODO: NOT property status !!!
if($_POST['status'] != 'draft')
{
}
//
Model_Offers::saveOfferDate($_POST['offer_id']);
//
$body = $this->action_sendOffer($_POST['offer_id'], $_POST['send_options'], $lang);
// $body .= "\r\n" . $_POST['send_free_message'];
if($_POST['send_options'] != 'none')
{
$mailer = email::connect();
// $mailer->registerPLugin(new Swift_Plugins_FilterPlugin('', $this->emailsBlacklist));
$subject = __ ( 'Quote for inquire ID: ' ).$_POST['offer_id'];
$body_temp = (!empty($_POST['send_free_message']))?$_POST['send_free_message'].'<hr />':'';
$body = $body_temp.$body;
$to = Model_Offers::getEmail($_POST['offer_id']);
$cc_to = Model_Offers::getCcEmail($_POST['offer_id']);
$from = Helper_Emails::$company_mail;
if($_POST['send_options'] == 'PDF')
{
//
$path = $_SERVER['DOCUMENT_ROOT'].'/pdfs/';
$attachment = Swift_Attachment::fromPath($path.'offer_'.$_POST['offer_id'].'.pdf');
if($cc_to != '') {
$message_swift = Swift_Message::newInstance ( $subject, $body , "text/html" )
->setContentType("application/pdf")
->attach($attachment)
->setFrom ( $from )
->setTo ( $to )
->setCc ($cc_to);
} else {
$message_swift = Swift_Message::newInstance ( $subject, $body , "text/html" )
->setContentType("application/pdf")
->attach($attachment)
->setFrom ( $from )
->setTo ( $to );
}
//
try {
if($mailer->send($message_swift))
{
// Model_QuoteOptions::changeStatusByOfferId($_POST['offer_id'], 'sent', false);
unlink($path.'offer_'.$_POST['offer_id'].'.pdf');
print 'success';
} else {
$change_statuses = false;
print 'error';
}
} catch (Exception $ex) {
}
} else {
if($cc_to != '') {
$message_swift = Swift_Message::newInstance ( $subject, $body , "text/html" )->setFrom ( $from )->setTo ( $to )->setCc($cc_to);
} else {
$message_swift = Swift_Message::newInstance ( $subject, $body , "text/html" )->setFrom ( $from )->setTo ( $to );
}
try {
if($mailer->send($message_swift))
{
print 'success';
} else {
$change_statuses = false;
print 'error';
}
} catch (Exception $ex) {
}
}
}
if($change_statuses === true)
{
//Change status of offer and inquiry
if($atm != false) {
//Change status of sent options
if(!empty($_POST['options']) AND is_array($_POST['options'])) {
Model_QuoteOptions::changeStatusByOfferId($_POST['offer_id'], 'sent', false, $_POST['options'], $atm);
}
// if(Model_QuoteOptions::checkIfAllSent($_POST['offer_id'], $atm)) {
Model_AlternativeOffers::updateAlternativeOffer($_POST['offer_id'], $atm, array('status' => 'completed'));
// Model_QuoteGeneralInfo::changeStatusQuote($_POST['offer_id'], 'sent', $_POST['quote_general_info_id']);
// }
} else {
//Change status of sent options
if(!empty($_POST['options']) AND is_array($_POST['options'])) {
Model_QuoteOptions::changeStatusByOfferId($_POST['offer_id'], 'sent', false, $_POST['options']);
}
}
print 'success';
}
else {
print 'error';
}
}
}
//