AnswerBun.com

How to post checkout data to component using Ajax?

Joomla Asked by askerman on September 5, 2021

$.ajax({
    url: Joomla.getOptions('system.paths').base+'/index.php?option=mypage&view=cartcheckout&task=cartcheckout_autoSave&tmpl=component&stepId='+stepId,
    type: 'POST',
    //async:false,
    data:values,
    dataType: 'json',

    success: function(response)
    {
        // do something
    },
    error: function(response)
    {
        // show ckout error msg
        console.log(' ERROR!!' );
        return e.preventDefault();
    }
});

My Joomla version is 3.9.3 Stable.
I am getting error message on console

ERROR!!

Is my url correct?

Joomla.getOptions('system.paths').base+'/index.php?option=mypage&view=cartcheckout&task=cartcheckout_autoSave&tmpl=component&stepId='+stepId

How can I solve this problem?

One Answer

I would define the url simply like the following:

url:'index.php?option=com_mypage&view=cartcheckout&task=autoSave&tmpl=component&stepId='+stepId,

(If in the console you would see error due to double slash in the ajax request url, then try it also without slash at the beginning of the url)(And as @Sharky pointed to it in the comment, if the url starts without the leading slash, then the url will always point to the root, even if Joomla is intalled in a subfolder).

It should work this way. In the above, you can see that the first segment of the url (after index.php?) starts with com_mypage as it has to be your component name (or the component name which you communicate with). It will never work if it is just a page. It must be like: option=com_virtuemart or option=com_j2store or some other component name.

The other parts of the url look OK. (However, the task segment should be &task=mycontrollerfunction of the component).

I just do not see any reason to define the base path in the ajax url if you start this call from inside Joomla, it’s just totally unnecessary (and it will never work the way you tried, since in jQuery it does not mean anything).

I mean in jQuery you could start your url with the base like:

window.location.protocol + "//" + window.location.host + “/index.php?...”

But for this ajax call you really do not need that.

Answered by Zollie on September 5, 2021

Add your own answers!

Related Questions

Add field to menu settings to output open graph image

1  Asked on December 30, 2021 by mano-meter

   

Edited css not updated in XAMPP

1  Asked on December 9, 2021 by advait-varma

     

Update from 3.9.x to 4.x

2  Asked on November 27, 2021 by lovntola

       

Other files overriding my template css with bootstrap?

1  Asked on November 19, 2021 by matthiasdunkel

   

Javascript accordion with anchors for joomla

1  Asked on November 5, 2021 by fruit_alchemist

   

Cannot Connect To MSSQL Server

3  Asked on September 5, 2021 by jamesmandatory

       

PlotALOT RSForm Query showing only one result

1  Asked on September 5, 2021 by gart

       

Getting module parameters in AJAX call using module id

1  Asked on September 5, 2021 by user1616338

     

Pop up AcyMailing subscription form

1  Asked on September 5, 2021 by ygiorgos

       

Override 3d party extension plugin method

0  Asked on September 5, 2021 by dmitry-zar

 

Ask a Question

Get help from others!

© 2023 AnswerBun.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP