Follow us on Twitter X-Cart on Facebook Wiki
Shopping cart software Solutions for online shops and malls

Dealing with ajax Request

 
Reply
   X-Cart forums > X-Cart 5 > General questions (X-Cart 5)
 
Thread Tools Search this Thread
  #1  
Old 03-14-2018, 02:49 AM
 
Soptareanu Alex Soptareanu Alex is offline
 

Member
  
Join Date: Sep 2016
Posts: 24
 

Default Dealing with ajax Request

I need to show a message on page after an ajax request is done. In my controller I use \XLite\Core\TopMessage::addInfo() interface, but the message I can see only if I reload the page after recive the response from server.
This is my controller :
if($this->isAJAX()){

$return = array(
'deliveryDate' => 'Some data',
'orderId' => 'Some data
);

$return = json_encode($return);
header('Content-Type: application/json; charset=UTF-8');
header('Content-Lenght: '.strlen($return));
header('ETag:' . md5($return));

\XLite\Core\TopMessage::addInfo(
'Your delivery date is ' . date('d-M-Y', $deliveryDate)
);

echo $return;
}

die();
}

And this is the function responsable to do the ajax request
function changeDate(_deliveryDate, _orderId){
//console.log(_deliveryDate);
//popup.openAsWait();
var shippingMethods = jQuery('.embed_calendar');
assignShadeOverlay(shippingMethods, true);
core.post(
URLHandler.buildURL({
target : 'calendar',
action : 'changedate',
deliveryDate: _deliveryDate,
orderId : _orderId
})
).done(function(response){
//console.log(response);
//popup.close();
var shippingMethods = jQuery('.embed_calendar');
unassignShadeOverlay(shippingMethods, true);
})
}

Is there a posibility to view the message after the request is done in this mode ?
__________________
alex
Reply With Quote
  #2  
Old 03-15-2018, 05:36 AM
  tony_sologubov's Avatar 
tony_sologubov tony_sologubov is offline
 

X-Cart team
  
Join Date: Jan 2009
Posts: 2,431
 

Default Re: Dealing with ajax Request

Hi @Alex,

Add the following code:
Code:
$this->translateTopMessagesToHTTPHeaders();

anywhere after this one:
Code:
\XLite\Core\TopMessage::addInfo( 'Your delivery date is ' . date('d-M-Y', $deliveryDate) );

in your controller class.

Tony

Quote:
Originally Posted by Soptareanu Alex
I need to show a message on page after an ajax request is done. In my controller I use \XLite\Core\TopMessage::addInfo() interface, but the message I can see only if I reload the page after recive the response from server.
This is my controller :
if($this->isAJAX()){

$return = array(
'deliveryDate' => 'Some data',
'orderId' => 'Some data
);

$return = json_encode($return);
header('Content-Type: application/json; charset=UTF-8');
header('Content-Lenght: '.strlen($return));
header('ETag:' . md5($return));

\XLite\Core\TopMessage::addInfo(
'Your delivery date is ' . date('d-M-Y', $deliveryDate)
);

echo $return;
}

die();
}

And this is the function responsable to do the ajax request
function changeDate(_deliveryDate, _orderId){
//console.log(_deliveryDate);
//popup.openAsWait();
var shippingMethods = jQuery('.embed_calendar');
assignShadeOverlay(shippingMethods, true);
core.post(
URLHandler.buildURL({
target : 'calendar',
action : 'changedate',
deliveryDate: _deliveryDate,
orderId : _orderId
})
).done(function(response){
//console.log(response);
//popup.close();
var shippingMethods = jQuery('.embed_calendar');
unassignShadeOverlay(shippingMethods, true);
})
}

Is there a posibility to view the message after the request is done in this mode ?
__________________
Found a bug in X-Cart? Post it to our bug tracker!
Know how to make X-Cart better? Suggest an idea!
Reply With Quote

The following user thanks tony_sologubov for this useful post:
Soptareanu Alex (03-15-2018)
Reply
   X-Cart forums > X-Cart 5 > General questions (X-Cart 5)


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -8. The time now is 04:27 AM.

   

 
X-Cart forums © 2001-2020