XF 2.2 Ajax Request(s)

RisteDimitrievski

Active member
JavaScript:
XF.ajax(ajaxUrl,{
                method:'POST',
                data:{metamaskid:Moralis.User.current()['id']},
                error:function(xhr){
                    console.log(xhr.statusText);
                },
                success:function(xhr){
                    console.log(xhr);
                }
            });

How can i submit ajax request to my controller. i've tried with $.ajax, but it gives me error 400 which may means by missing CSRF token. And i don't have any idea how can i get CSRF token from XF js functions?
 
Calls to XF.ajax will include the CSRF token automatically, assuming XF.config.csrf is available on the document (which it is by default on virtually every page).
 
Calls to XF.ajax will include the CSRF token automatically, assuming XF.config.csrf is available on the document (which it is by default on virtually every page).
Yea, but the problem is that when i want to submit my data over XF.ajax the data is not submitting nor even gives any error message.
 
Even when you check the response from developer tools? You would have to post more complete details and code, if so. I don't think there's any situation where XF would return a 400 response without a corresponding error message, and it's impossible for anyone else to debug without further information.
 
Even when you check the response from developer tools? You would have to post more complete details and code, if so. I don't think there's any situation where XF would return a 400 response without a corresponding error message, and it's impossible for anyone else to debug without further information.
I get now this error
1646604491573.webp

JavaScript:
 var ajaxurl = ''+XF.config.url.fullBase+"/metamask_session";
            XF.ajax({
                url:ajaxurl,
                method:'POST',
                data:{metamaskid:Moralis.User.current()['id']},
                error:function(xhr){
                    console.log(xhr.statusText);
                },
                success:function(xhr){
                    console.log(xhr);
                }
            });
 
Actually, review the signature for XF.ajax:
JavaScript:
function(method, url, data, successCallback, options)

You'd need to do something like:
JavaScript:
XF.ajax('post', ajaxUrl, {metamaskid: 'whatever'}, function (data) {
    // success callback
});
 
Top Bottom