Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bad ajax call #65

Closed
gonzaloebiz opened this issue Aug 11, 2017 · 12 comments
Closed

Bad ajax call #65

gonzaloebiz opened this issue Aug 11, 2017 · 12 comments
Assignees

Comments

@gonzaloebiz
Copy link
Collaborator

Hello,
I recently installed Mailchimp for Magento 2 on a site I programmed. First thing I noticed was that there was a 404 for an ajax request on the cart page. I was able to fix this error, by altering this file:

/app/code/Ebizmarts/MailChimp/view/frontend/web/js/mailchimpjs.js

Changing the url of the ajax request from this:
url: 'mailchimp/script/get',

To:
url: '/mailchimp/Script/Get',

While I don’t believe it’s case sensitive, the main fix was adding in the slash in the beginning so that the ajax request goes to the correct “Get” class in your module.

If this is a legit fix, would it be possible for you guys to roll this into a new version so that when I use this module in the future, I don’t have to keep remembering to make this change?

Thanks!

Michael Zenner | Senior Developer

@mikehenze
Copy link

This does not fix it.

The script now looks for:
www.example.com/checkout/mailchimp/script/get
and (I think) this should be:
www.example.com/mailchimp/script/get

@gonzaloebiz
Copy link
Collaborator Author

Hi @mikehenze

please be sure that the modified mailchimpjs.js is loaded

@mikehenze
Copy link

It is.
I did this after replacing the file:
rm -rf pub/static/_requirejs pub/static/adminhtml pub/static/frontend var/cache/ var/composer_home/ var/generation/ var/page_cache/ var/view_preprocessed/
php bin/magento setup:di:compile
php bin/magento setup:static-content:deploy nl_NL
redis-cli flushall

@gonzaloebiz
Copy link
Collaborator Author

Open yoursiteurl/pub/static/frontend/Magento/luma/en_US/Ebizmarts_MailChimp/js/mailchimpjs.js and confirm that in the ajax call you have
url: '/mailchimp/script/get',

with an / at front

@mikehenze
Copy link

mikehenze commented Aug 11, 2017

It seems to be not working with minified js

mailchimpjs.min.js (does not work)
require(["jquery"],function($){$.ajax({url:'/mailchimp/script/get',type:'POST',dataType:'json',showLoader:false}).done(function(data){var imported=document.createElement('script');imported.src=data.url;document.head.appendChild(imported);});});

mailchimpjs.js (works)

require(["jquery"], function ($) {
    $.ajax({
        url: '/mailchimp/script/get',
        type: 'POST',
        dataType: 'json',
        showLoader: false
    }).done(function (data) {
        var imported = document.createElement('script');
        imported.src = data.url;
        document.head.appendChild(imported);

    });
});

@gonzaloebiz
Copy link
Collaborator Author

@mikehenze

works for me. I put magento in production mode, enabled Advanced/Developer/JavaScript Setting/Merge JavaScript Files and Advanced/Developer/JavaScript Setting/Minify JavaScript Files

rm -rf pub/static
bin/magento setup:static-content:deploy
bin/magento cache:clean

Try also only with Advanced/Developer/JavaScript Setting/Minify JavaScript Files and works.
Are you clear your browser cache?

@mikehenze
Copy link

According to Chrome console it is loaded the js from:
/static/_cache/merged/e07fa983f57f47d7bc4972a3710cc9ea.min.js
and there the "/" is still missing from the code.

So I guess running redis-cli flushall does not flush merged js/css
I flushed js from magento2 backend and now it loads the correct js and the ajax call is good.

@gonzaloebiz
Copy link
Collaborator Author

ok great

@lano-vargas
Copy link

lano-vargas commented Dec 13, 2017

I have installed sometime ago around Augost time and I didn't use until no!

Is there an update version with this bug fix if there is can you point to the fixed version please?

Never Mind I've checked this release: Release 1.0.25 it contains the "/" thanks.

@LucScu
Copy link

LucScu commented Feb 26, 2018

Why do you make a POST request and not a GET request?

@gonzaloebiz
Copy link
Collaborator Author

Hi @LucScu

take a look at #112

@LucScu
Copy link

LucScu commented Feb 26, 2018

ok, so i fix correctly by myself changing it to GET. Do you know when the version this fix will be released?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants