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

How to properly perform AJAX

 
Reply
   X-Cart forums > X-Cart 5 > Dev Questions (X-Cart 5)
 
Thread Tools Search this Thread
  #1  
Old 11-29-2017, 10:29 PM
 
Alex L Alex L is offline
 

Newbie
  
Join Date: Nov 2017
Posts: 3
 

Default How to properly perform AJAX

I am having trouble with using AJAX. I have controller class derived from AAdmin with following action:

Code:
protected function doActionMyAction() { $list = \XLite\Core\Request::getInstance()->idlist; echo $list; }

I also have this piece so that I do not get forbidden thrown at me when I attempt to call that action:

Code:
public static function defineFreeFormIdActions() { return array_merge( parent::defineFreeFormIdActions(), array('myaction') ); }

In my javascript file I have this piece to perform AJAX call:

Code:
var str = "TEST STRING"; core.post( URLHandler.buildURL({ target: "crosscheck_order", action: "myaction" }), function (XMLHttpRequest, textStatus, data, valid) { console.log(data); }, { idlist: str} );

Instead of getting value of "str" in my console, I instead get raw html of the entire default template for this controller. Any tips on what I am doing wrong are very appreciated!
__________________
X-Cart Ultimate 5.2.14
Reply With Quote
  #2  
Old 11-30-2017, 01:44 AM
  qualiteam's Avatar 
qualiteam qualiteam is offline
 

X-Guru
  
Join Date: Dec 2010
Posts: 6,373
 

Default Re: How to properly perform AJAX

Please check how \XLite\Controller\Customer\Rest and \XLite\Controller\Customer\Autocomplete controllers return JSON data.
I think this should help.
__________________
Alex Solovev,
Qualiteam

---

User manual Video tutorials X-Cart FAQ

You are welcome to press "Thanks" button
if you find this post useful

Click here to learn how to apply patches

X-Cart Extensions
Reply With Quote

The following user thanks qualiteam for this useful post:
Alex L (12-01-2017)
  #3  
Old 12-01-2017, 08:01 PM
 
Alex L Alex L is offline
 

Newbie
  
Join Date: Nov 2017
Posts: 3
 

Default Re: How to properly perform AJAX

Quote:
Originally Posted by qualiteam
Please check how \XLite\Controller\Customer\Rest and \XLite\Controller\Customer\Autocomplete controllers return JSON data.
I think this should help.

Thank you for your reply! I completely forgot about adding headers, but adding them did not solve my issue. I still kept receiving raw html of page on which my script was being executed. I solved this by using jQuery.ajax() post method instead and it worked just fine. But I still do not understand why I could not get core.post() to work.
__________________
X-Cart Ultimate 5.2.14
Reply With Quote
Reply
   X-Cart forums > X-Cart 5 > Dev Questions (X-Cart 5)



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 09:20 AM.

   

 
X-Cart forums © 2001-2020